0

在我使用的编码标准中,我们使用 2 个空格进行缩进

<!-- Tabs should represent 2 spaces. -->
<arg name="tab-width" value="2"/>

<!-- Set the default indent value and force spaces instead of tabs -->
<rule ref="WordPress">
    <exclude name="Generic.WhiteSpace.DisallowSpaceIndent" />
</rule>
<rule ref="Generic.WhiteSpace.ScopeIndent">
  <properties>
    <property name="indent" value="2"/>
    <property name="tabIndent" value="false"/>
  </properties>
</rule>
<rule ref="Generic.WhiteSpace.DisallowTabIndent" />

这通常工作正常,但如果我有,例如这个

<?php

class MyClass{
  public function my_function() {
    add_submenu_page(
      'my-top-level-slug',
      'My Custom Page',
      'My Custom Page',
      'manage_options',
      'my-top-level-slug'
    );
  }
}

add_submenu_page()我得到函数的参数在哪里

多行函数调用未正确缩进;预计有 8 个空格,但找到了 6 个

所以“正确”看起来像

<?php

class MyClass{
  public function my_function() {
    add_submenu_page(
        'my-top-level-slug',
        'My Custom Page',
        'My Custom Page',
        'manage_options',
        'my-top-level-slug'
    );
  }
}

但这两个空格太多了。我在github上发现了一些问题,但没有找到解决方案。

如何解决这个问题?

4

1 回答 1

1

不幸的是,PHPCS 还没有共享配置设置,因此您需要为其他报告错误的嗅探器设置缩进设置。

如果您将-s命令行参数添加到 PHPCS,您将获得每个错误消息的嗅探代码。该代码告诉您哪个嗅探报告了错误并需要更改。

在这种情况下,我认为是PEAR.Functions.FunctionCallSignature嗅觉。

可以在此处找到此嗅探的设置:https ://github.com/squizlabs/PHP_CodeSniffer/wiki/Customisable-Sniff-Properties#pearfunctionsfunctioncallsignature

如果是这样,您需要将其添加到您的规则集中:

<rule ref="PEAR.Functions.FunctionCallSignature">
  <properties>
    <property name="indent" value="2"/>
  </properties>
</rule
于 2017-09-19T03:55:46.000 回答