'Syntax error near unexpected token' PHP 代码嗅探器.xml文件中没有语法错误的错误



系统上安装了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 中:

  1. 打开首选项
  2. 导航到 Language & Frameworks> PHP> Code 嗅探器
  3. 单击配置旁边的 [...]
  4. 验证 phpc 的路径

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

相关内容

最新更新