系统上安装了phpcs
,代码嗅探从命令行工作正常。
phpcs --extensions=php /path/to/code.php`
^ 工作正常。
对于 PHP Storm IDE,我在设置中指定了规则集.xml文件的位置,如下所示:
Cmd
+,
>PHP Code Sniffer validation
>Coding standard
>Custom
>规则集的路径.xml
但是,我收到此错误:
PHP Code Sniffer
phpcs: /Users/gketkar/code-sniffer/Blah/ruleset.xml: line 1: syntax error near unexpected token `newline'
/Users/gketkar/code-sniffer/Blah/ruleset.xml: line 1: `<?xml version="1.0"?>'
更新: 规则集.xml文件如下所示:
<?xml version="1.0"?>
<ruleset name="Blah">
<description>Blah Coding Standards</description>
<rule ref="Generic">
<exclude name="Generic.Formatting.SpaceAfterCast.NoSpace"/>
<exclude name="Generic.PHP.DeprecatedFunctions"/>
<exclude name="Generic.PHP.DisallowShortOpenTag.EchoFound"/>
<exclude name="Generic.PHP.UpperCaseConstant.Found"/>
</rule>
</ruleset>
这看起来您已经将ruleset.xml
加载到应该具有phpcs
二进制文件的设置中。 在 PHPStorm 中:
- 打开首选项
- 导航到 Language & Frameworks> PHP> Code 嗅探器
- 单击配置旁边的 [...]
- 验证 phpc 的路径
确保路径指向phpcs
文件,而不是ruleset.xml
文件。 如果您没有,请尝试 https://packagist.org/packages/squizlabs/php_codesniffer