【发布时间】:2018-07-21 18:51:42
【问题描述】:
你可以format on savePHP 以及Beautify extension of Visual Code 吗?如果是,你如何设置它?如果不是,哪个扩展可以做到这一点?
【问题讨论】:
标签: php formatting visual-studio-code
你可以format on savePHP 以及Beautify extension of Visual Code 吗?如果是,你如何设置它?如果不是,哪个扩展可以做到这一点?
【问题讨论】:
标签: php formatting visual-studio-code
您可以使用vscode-php-formatter 扩展名,它将按需(通过键绑定)或保存时格式化您的 PHP 代码。
它是 PHP Coding Standards Fixer 的包装器,正如您所见,它允许非常灵活的配置,因此您可以根据自己的喜好进行调整。
要添加自定义配置,请创建一个.php_cs 文件,将其添加到您的参数设置中:
phpformatter.arguments: ["--custom-config=/path/to/file/config.php_cs"]
并使用您的自定义规则创建一个文件:
<?php
$finder = Symfony\Component\Finder\Finder::create()
->files()
->in(__DIR__)
->exclude('vendor')
->exclude('resources/views')
->exclude('storage')
->exclude('public')
->notName("*.txt")
->ignoreDotFiles(true)
->ignoreVCS(true);
$fixers = [
'-psr0',
'-php_closing_tag',
'blankline_after_open_tag',
// more custom rules
];
return Symfony\CS\Config\Config::create()
->level(Symfony\CS\FixerInterface::PSR2_LEVEL)
->fixers($fixers)
->finder($finder)
->setUsingCache(true);
【讨论】:
试试 Ben Mewburn 的插件 PHP Intelephense。正如手册所说:
无损 PSR-12 兼容文档/范围格式。组合格式 HTML/PHP/JS/CSS 文件也是。
【讨论】: