PHPcs xml 配置禁用一些规则

muu*_*uuv 5 php phpcodesniffer phpcs

我了解如何使用 xml 配置 phpcs,但找不到如何禁用某些嗅探。这是我当前的配置(甚至不知道这是否正确):

\n\n
<?xml version="1.0" encoding="UTF-8"?>\n<ruleset name="custom" \n  xmlns="http://pmd.sf.net/ruleset/1.0.0" \n  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">\n  <rule ref="rulesets/codesize.xml"/>\n  <rule ref="rulesets/controversial.xml/Superglobals"/>\n  <rule ref="rulesets/controversial.xml/CamelCaseParameterName"/>\n  <rule ref="rulesets/controversial.xml/CamelCaseVariableName"/>\n  <rule ref="rulesets/design.xml"/>\n  <rule ref="rulesets/naming.xml/ShortMethodName"/>\n  <rule ref="rulesets/naming.xml/ConstructorWithNameAsEnclosingClass"/>\n  <rule ref="rulesets/naming.xml/ConstantNamingConventions"/>\n  <rule ref="rulesets/naming.xml/BooleanGetMethodName">\n    <properties>\n      <property name="checkParameterizedMethods" value="true"/>\n    </properties>\n  </rule>\n  <rule ref="rulesets/unusedcode.xml"/>\n\n  <arg name="tab-width" value="2"/>\n  <rule ref="Generic.WhiteSpace.ScopeIndent">\n    <properties>\n      <property name="indent" value="2"/>\n    </properties>\n  </rule>\n\n  <rule ref="Generic.Files.LineLength">\n    <properties>\n      <property name="lineLimit" value="140"/>\n      <property name="absoluteLineLimit" value="0"/>\n    </properties>\n  </rule>\n</ruleset>\n
Run Code Online (Sandbox Code Playgroud)\n\n

我想禁用这些:

\n\n
    \n
  • [phpcs] @copyright tag must contain a year and the name of the copyright holder所有文档评论嗅探(我不需要\xe2\x80\x98t需要它们)
  • \n
  • [phpcs] PHP version not specified
  • \n
  • [phpcs] There must be exactly one blank line before the tags in a doc comment
  • \n
  • [phpcs] The open comment tag must be the only content on the line
  • \n
  • [phpcs] Missing short description in doc comment
  • \n
  • [phpcs] The close comment tag must be the only content on the line
  • \n
  • [phpcs] Line indented incorrectly; expected at least 4 spaces, found 2我用了两个空格!
  • \n
  • [phpcs] Missing file doc comment
  • \n
  • [phpcs] Line exceeds 85 characters; contains 91 characters我想要最多 140
  • \n
\n\n

如果我想添加更多,我可以在哪里搜索可能的配置?

\n

Hyd*_* B. 8

忽略规则的另一种方法是使用标志--exclude。

vendor/bin/phpcs --standard=PSR2  --exclude=Generic.Files.LineLength,Generic.WhiteSpace.ScopeIndent app/
Run Code Online (Sandbox Code Playgroud)

为了找到要排除的规则名称,请在以下目录中找到相应的规则集:

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>
Run Code Online (Sandbox Code Playgroud)

与创建单独的规则集相比,它更快、更省事。


mik*_*e42 5

我建议您找到最相似的规则集,并制作一份不包含指定嗅探的副本。

带注释的规则集.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>
Run Code Online (Sandbox Code Playgroud)

这里的大部分工作是找出每个嗅探是如何被包含的,如果它没有在其他地方列出,可以通过 GitHub 搜索消息(示例)找到它。


muu*_*uuv 0

谢谢大家,我找到了一种方法:http ://edorian.github.io/php-coding-standard-generator/#phpcs

之前尝试过,但不起作用,发现我必须单击 phpcs(第一眼看上去就被选中了)。