4

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

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

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

4

3 回答 3

4

忽略规则的另一种方法是使用--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>

它比创建单独的规则集更快、更简单。

于 2019-08-24T07:42:01.263 回答
3

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

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 搜索消息(示例)找到它。

于 2018-06-20T10:38:55.950 回答
0

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

之前试过,没用,发现我必须点击phpcs(第一时间看起来被选中)。

于 2018-06-20T13:42:48.007 回答