PHPcs xml 配置禁用一些规则
PHPcs xml config disable some rules
我了解如何使用 xml 配置 phpcs,但找不到如何禁用某些嗅探。这是我当前的 conf(甚至不知道这是否正确):
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="custom"
xmlns="http://pmd.sf.net/ruleset/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd" xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
<rule ref="rulesets/codesize.xml"/>
<rule ref="rulesets/controversial.xml/Superglobals"/>
<rule ref="rulesets/controversial.xml/CamelCaseParameterName"/>
<rule ref="rulesets/controversial.xml/CamelCaseVariableName"/>
<rule ref="rulesets/design.xml"/>
<rule ref="rulesets/naming.xml/ShortMethodName"/>
<rule ref="rulesets/naming.xml/ConstructorWithNameAsEnclosingClass"/>
<rule ref="rulesets/naming.xml/ConstantNamingConventions"/>
<rule ref="rulesets/naming.xml/BooleanGetMethodName">
<properties>
<property name="checkParameterizedMethods" value="true"/>
</properties>
</rule>
<rule ref="rulesets/unusedcode.xml"/>
<arg name="tab-width" value="2"/>
<rule ref="Generic.WhiteSpace.ScopeIndent">
<properties>
<property name="indent" value="2"/>
</properties>
</rule>
<rule ref="Generic.Files.LineLength">
<properties>
<property name="lineLimit" value="140"/>
<property name="absoluteLineLimit" value="0"/>
</properties>
</rule>
</ruleset>
我想禁用这些:
[phpcs] @copyright tag must contain a year and the name of the copyright holder
所有文档评论嗅探(我不需要它们)
[phpcs] PHP version not specified
[phpcs] There must be exactly one blank line before the tags in a doc comment
[phpcs] The open comment tag must be the only content on the line
[phpcs] Missing short description in doc comment
[phpcs] The close comment tag must be the only content on the line
[phpcs] Line indented incorrectly; expected at least 4 spaces, found 2
我用了两个空格!
[phpcs] Missing file doc comment
[phpcs] Line exceeds 85 characters; contains 91 characters
我想最多 140
如果我想添加更多,我可以在哪里搜索可能的配置?
我建议尽可能找到最相似的规则集,并制作一个不包含指定嗅探的副本。
Annotated ruleset.xml 示例包括一个从规则中排除某些嗅探的块,以及自定义规则集的使用。
<!--
Include all sniffs in the Squiz standard except one. Note that
the name of the sniff being excluded is the code that the sniff
is given by PHP_CodeSniffer and is based on the file name and
path of the sniff class. You can display these codes using the
-s command line argument when checking a file.
-->
<rule ref="Squiz">
<exclude name="Squiz.PHP.CommentedOutCode"/>
</rule>
这里的大部分工作是找出每个嗅探是如何被包含的,如果它没有在其他任何地方列出,可以通过 GitHub 搜索消息 (example) 找到它。
感谢大家,我找到了一个方法:http://edorian.github.io/php-coding-standard-generator/#phpcs
之前试过,不行,发现必须点phpcs(第一时间看起来选中了)
另一种忽略规则的方法是使用 --exclude
标志。
vendor/bin/phpcs --standard=PSR2 --exclude=Generic.Files.LineLength,Generic.WhiteSpace.ScopeIndent app/
为了找到要排除的规则名称,请在以下目录中找到相应的规则集:
vendor/squizlabs/php_codesniffer/src/Standards/<coding standard>/ruleset.xml
规则名称将在 ref 节点中:
<rule ref="Generic.Files.LineLength">
<properties>
<property name="lineLimit" value="120"/>
<property name="absoluteLineLimit" value="0"/>
</properties>
</rule>
它比创建单独的规则集更快更简单。
我了解如何使用 xml 配置 phpcs,但找不到如何禁用某些嗅探。这是我当前的 conf(甚至不知道这是否正确):
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="custom"
xmlns="http://pmd.sf.net/ruleset/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd" xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
<rule ref="rulesets/codesize.xml"/>
<rule ref="rulesets/controversial.xml/Superglobals"/>
<rule ref="rulesets/controversial.xml/CamelCaseParameterName"/>
<rule ref="rulesets/controversial.xml/CamelCaseVariableName"/>
<rule ref="rulesets/design.xml"/>
<rule ref="rulesets/naming.xml/ShortMethodName"/>
<rule ref="rulesets/naming.xml/ConstructorWithNameAsEnclosingClass"/>
<rule ref="rulesets/naming.xml/ConstantNamingConventions"/>
<rule ref="rulesets/naming.xml/BooleanGetMethodName">
<properties>
<property name="checkParameterizedMethods" value="true"/>
</properties>
</rule>
<rule ref="rulesets/unusedcode.xml"/>
<arg name="tab-width" value="2"/>
<rule ref="Generic.WhiteSpace.ScopeIndent">
<properties>
<property name="indent" value="2"/>
</properties>
</rule>
<rule ref="Generic.Files.LineLength">
<properties>
<property name="lineLimit" value="140"/>
<property name="absoluteLineLimit" value="0"/>
</properties>
</rule>
</ruleset>
我想禁用这些:
[phpcs] @copyright tag must contain a year and the name of the copyright holder
所有文档评论嗅探(我不需要它们)[phpcs] PHP version not specified
[phpcs] There must be exactly one blank line before the tags in a doc comment
[phpcs] The open comment tag must be the only content on the line
[phpcs] Missing short description in doc comment
[phpcs] The close comment tag must be the only content on the line
[phpcs] Line indented incorrectly; expected at least 4 spaces, found 2
我用了两个空格![phpcs] Missing file doc comment
[phpcs] Line exceeds 85 characters; contains 91 characters
我想最多 140
如果我想添加更多,我可以在哪里搜索可能的配置?
我建议尽可能找到最相似的规则集,并制作一个不包含指定嗅探的副本。
Annotated ruleset.xml 示例包括一个从规则中排除某些嗅探的块,以及自定义规则集的使用。
<!--
Include all sniffs in the Squiz standard except one. Note that
the name of the sniff being excluded is the code that the sniff
is given by PHP_CodeSniffer and is based on the file name and
path of the sniff class. You can display these codes using the
-s command line argument when checking a file.
-->
<rule ref="Squiz">
<exclude name="Squiz.PHP.CommentedOutCode"/>
</rule>
这里的大部分工作是找出每个嗅探是如何被包含的,如果它没有在其他任何地方列出,可以通过 GitHub 搜索消息 (example) 找到它。
感谢大家,我找到了一个方法:http://edorian.github.io/php-coding-standard-generator/#phpcs
之前试过,不行,发现必须点phpcs(第一时间看起来选中了)
另一种忽略规则的方法是使用 --exclude
标志。
vendor/bin/phpcs --standard=PSR2 --exclude=Generic.Files.LineLength,Generic.WhiteSpace.ScopeIndent app/
为了找到要排除的规则名称,请在以下目录中找到相应的规则集:
vendor/squizlabs/php_codesniffer/src/Standards/<coding standard>/ruleset.xml
规则名称将在 ref 节点中:
<rule ref="Generic.Files.LineLength">
<properties>
<property name="lineLimit" value="120"/>
<property name="absoluteLineLimit" value="0"/>
</properties>
</rule>
它比创建单独的规则集更快更简单。