phpcs - 防止显示“多行函数调用的左括号必须是行末内容”

4

这段代码出现了错误:

$posts = App\Post::whereHas('comments', function (Builder $query) {
    $query->where('content', 'like', 'foo%');
});

我正在使用phpcs vscode,并且需要所有默认规则,但不需要其中的一个规则!

请告诉我如何:

  1. 编写包含所有默认规则的phpcs
  2. 如何排除这个规则

检查 { 后面是否有空格。 - u_mulder
@u_mulder 检查过了,红线在 App\Post::whereHas( 下面,谢谢。 - Ali
1
如果可以的话,你应该将默认编码标准更改为PSR2(PEAR是默认值)。 - Jeto
2
@Jeto 谢谢,这个解决了我的问题!截至2019年8月10日,PSR-2已被标记为已弃用。现在推荐使用PSR-12作为替代方案。因此:phpcs --config-set default_standard PSR12 - Pepijn Olivier
2个回答

1
你可以使用具有以下内容的 ruleset.xml
<?xml version="1.0"?>
<ruleset name="MyStandard">
    <description>My custom coding standard.</description>
    <rule ref="PEAR">
        <exclude name="PEAR.Functions.FunctionCallSignature.ContentAfterOpenBracket"/>
        <exclude name="PEAR.Functions.FunctionCallSignature.CloseBracketLine"/>
    </rule>
</ruleset>

然后在 VS Code 中的 Phpcs: standards settings.json 中添加此行。

{
    "phpcs.standard": "path_to_your_standard/ruleset.xml"
}

关于规则集的更多信息可以在这里找到


0

您可以使用包含此内容的ruleset.xml文件

<?xml version="1.0"?>
<ruleset name="Oximox">
   <!--
      The name attribute of the ruleset tag is displayed
      when running PHP_CodeSniffer with the -v command line
      argument. The description tag below is not displayed anywhere
      except in this file, so it can contain information for
      developers who may change this file in the future.
   -->
   <description>Custom Coding Standards</description>

   <!--
      Include all sniffs in the PSR2 standard. Note that the
      path to the standard does not have to be specified as the
      PSR2 standard exists inside the PHP_CodeSniffer install
      directory.
   -->
   <rule ref="PSR2"/>

   <rule ref="PSR2">
        <exclude name="PSR2.Functions.FunctionCallSignature.ContentAfterOpenBracket"/>
        <exclude name="PSR2.Functions.FunctionCallSignature.CloseBracketLine"/>
    </rule>
</ruleset>

这对我有用。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接