1

phpcs安装在系统上,代码嗅探可以从命令行正常工作。

phpcs --extensions=php /path/to/code.php` 

^ 工作正常。

对于 PHP Storm IDE,我在设置中指定了 ruleset.xml 文件的位置,如下所示:

Cmd+ ,> PHP Code Sniffer validation> Coding standard> Custom> ruleset.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"?>'

更新:ruleset.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>
4

1 回答 1

0

这看起来像您已ruleset.xml加载到应该具有phpcs二进制文件的设置中。在 PHPStorm 中:

  1. 打开首选项
  2. 导航到语言和框架 > PHP > 代码嗅探器
  3. 单击配置旁边的 [...]
  4. 验证 phpcs 的路径

确保路径指向phpcs文件而不是ruleset.xml文件。如果您没有,请尝试https://packagist.org/packages/squizlabs/php_codesniffer

于 2017-10-25T17:41:25.917 回答