dex*_*vip 28 php continuous-integration pear codesniffer jenkins
我一直在使用jenkins的PHP_CodeSniffer,我的build.xml是为phpcs配置的,如下所示
<target name="phpcs">
<exec executable="phpcs">
<arg line="--report=checkstyle --report-file=${basedir}/build/logs/checkstyle.xml --standard=Zend ${source}"/>
</exec>
</target>
Run Code Online (Sandbox Code Playgroud)
我想忽略以下警告
FOUND 0 ERROR(S) AND 1 WARNING(S) AFFECTING 1 LINE(S)
--------------------------------------------------------------------------------
117 | WARNING | Line exceeds 80 characters; contains 85 characters
--------------------------------------------------------------------------------
Run Code Online (Sandbox Code Playgroud)
我怎么能忽略行长警告?
Wri*_*ken 47
您可以创建自己的标准.Zend的一个非常简单(这是/usr/share/php/PHP/CodeSniffer/Standards/Zend/ruleset.xml在我用Debian安装后的Debian安装中).基于它创建另一个,但忽略行长度位:
<?xml version="1.0"?>
<ruleset name="Custom">
<description>Zend, but without linelength check.</description>
<rule ref="Zend">
<exclude name="Generic.Files.LineLength"/>
</rule>
</ruleset>
Run Code Online (Sandbox Code Playgroud)
并设置--standard=/path/to/your/ruleset.xml.
(可选)如果您只想在触发此计数之前计算字符数,请重新定义规则:
<!-- Lines can be N chars long (warnings), errors at M chars -->
<rule ref="Generic.Files.LineLength">
<properties>
<property name="lineLimit" value="N"/>
<property name="absoluteLineLimit" value="M"/>
</properties>
</rule>
Run Code Online (Sandbox Code Playgroud)
Hyd*_* B. 13
忽略消息行超过 x 个字符的另一种方法是使用--exclude标志来排除规则。
vendor/bin/phpcs --standard=PSR2 --exclude=Generic.Files.LineLength 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)
与创建单独的规则集相比,它更快且更简单。
在 mac/linux 上查找文件 CodeSniffer/Standards/PEAR/ruleset.xml \xe2\x80\x93 您可以在终端中搜索:
\n\nlocate PEAR/ruleset.xml或者sudo find / -name "ruleset.xml"
然后您需要在ruleset.xml中找到以下行:
\n\n<!-- Lines can be 85 chars long, but never show errors -->\n<rule ref="Generic.Files.LineLength">\n<properties>\n<property name="lineLimit" value="85"/>\n<property name="absoluteLineLimit" value="0"/>\n</properties>\n</rule>
只需将数字 85(行的最大长度)更改为您想要的值即可。
请注意,phpc 的默认编码标准是 PEAR 标准。因此,您需要在此位置编辑ruleset.xml:CodeSniffer/Standards/PEAR/ruleset.xml
\n