Как я могу установить мой предпочтительный уровень отступа с помощью PHP CodeSniffer?

StackOverflow https://stackoverflow.com//questions/9650154

  •  11-12-2019
  •  | 
  •  

Вопрос

Я не хочу игнорировать уровень отступа.

Я хочу обеспечить соблюдение определенного уровня отступа, который не по умолчанию, 4.

Видимо это возможно:

Введите описание изображения здесь

Как?

Документация по этому материалу, похоже, усугубляет меня.

Это было полезно?

Решение

Apparently one way to do it is this: create a new "Standard", create a new ruleset.xml, then insert into that ruleset.xml file, an XML stanza that sets the property.

For example, (I'm on Windows so my backslashes are all backslashes and not fwd slashes)

cd \dev\phpcs\CodeSniffer
mkdir NewStandard

Within that directory, create ruleset.xml, containing this :

<?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>

The final stanza within the xml file sets the appropriate property.

To do this, you have to know that

A) the indenting sniff (rule) is PEAR.WhiteSpace.ScopeIndent

B) the property on that sniff is called indent.

Then, run phpcs as normal like so:

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

documentation:

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

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top