10

我不想忽略缩进级别。

我想强制执行一个不是默认的特定缩进级别,4。

显然这是可能的:

在此处输入图像描述

如何?

关于这些东西的文档似乎让我望而却步。

4

1 回答 1

6

显然,这样做的一种方法是:创建一个新的“标准”,创建一个新的 ruleset.xml,然后将一个用于设置属性的 XML 节插入到该 ruleset.xml 文件中。

例如,(我在 Windows 上,所以我的反斜杠都是反斜杠而不是 fwd 斜杠)

cd \dev\phpcs\CodeSniffer
mkdir NewStandard

在该目录中,创建 ruleset.xml,其中包含:

<?xml version="1.0"?>
<ruleset name="Custom Standard">
  <description>My custom coding standard</description>
  <rule ref="PEAR">
    <exclude name="PEAR.Commenting.ClassComment"/>
    <exclude name="PEAR.Commenting.FileComment"/>
    <exclude name="PEAR.Commenting.FunctionComment"/>
    <exclude name="PEAR.Commenting.InlineComment"/>
    <exclude name="PEAR.Classes.ClassDeclaration"/>
    <exclude name="Generic.Files.LineEndings"/>
  </rule>

  <rule ref="PEAR.WhiteSpace.ScopeIndent">
    <properties>
      <property name="indent" value="2"/>
    </properties>
  </rule>

</ruleset>

xml 文件中的最后一节设置适当的属性。

要做到这一点,你必须知道

A)缩进嗅探(规则)是 PEAR.WhiteSpace.ScopeIndent

B)那个嗅探的属性被称为indent

然后,像这样正常运行 phpcs:

\php\php.exe phpcs\scripts\phpcs --standard=NewStandard --report=emacs MyCode.php

文档:

http://pear.php.net/manual/en/package.php.php-codesniffer.annotated-ruleset.php

于 2012-03-10T21:35:19.103 回答