多行函数调用没有正确缩进

时间:2017-09-18 09:10:01

标签: php wordpress codesniffer phpcodesniffer

在我使用的编码标准中,我们使用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个

所以&#39;正确&#39;看起来像

<?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上发现了一些问题,但没有为此找到解决方案。

如何解决这个问题?

1 个答案:

答案 0 :(得分: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
相关问题