我理解phpcs是如何使用xml配置的,但无法找到如何禁用一些嗅探。这是我目前的工作(甚至不知道这是否正确):
<?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个如果我想添加更多,我可以在哪里搜索可能的配置?
发布于 2018-06-20 13:42:48
多亏了你们,我找到了一种方法:http://edorian.github.io/php-coding-standard-generator/#phpcs
以前试过,但它没有工作,并发现我必须点击phpcs (在第一分钟看被选中)。
发布于 2019-08-24 07:42:01
忽略规则的另一种方法是使用--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>它比创建单独的规则集更快&也更简单。
发布于 2018-06-20 10:38:55
我建议找到您能找到的最相似的规则集,并创建一个不包含指定嗅探的副本。
带注释的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搜索消息(示例)来找到它。
https://stackoverflow.com/questions/50944925
复制相似问题