如何忽略行长度 PHP_CodeSniffer
我一直在 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>
,如下所示 我想忽略以下警告
FOUND 0 ERROR(S) AND 1 WARNING(S) AFFECTING 1 LINE(S)
--------------------------------------------------------------------------------
117 | WARNING | Line exceeds 80 characters; contains 85 characters
--------------------------------------------------------------------------------
如何忽略行长度警告?
I have been using PHP_CodeSniffer with jenkins, my build.xml was configured for phpcs as below
<target name="phpcs">
<exec executable="phpcs">
<arg line="--report=checkstyle --report-file=${basedir}/build/logs/checkstyle.xml --standard=Zend ${source}"/>
</exec>
</target>
And I would like to ignore the following warning
FOUND 0 ERROR(S) AND 1 WARNING(S) AFFECTING 1 LINE(S)
--------------------------------------------------------------------------------
117 | WARNING | Line exceeds 80 characters; contains 85 characters
--------------------------------------------------------------------------------
How could I ignore the line length warning?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以创建自己的标准。 Zend 非常简单(在使用 PEAR 安装后,它位于我的 Debian 安装中的
/usr/share/php/PHP/CodeSniffer/Standards/Zend/ruleset.xml
中)。基于它创建另一个,但忽略行长度位:并设置
--standard=/path/to/your/ruleset.xml
。或者,如果您只想在触发此操作之前增加字符计数,请重新定义规则:
You could create your own standard. The Zend one is quite simple (this is at
/usr/share/php/PHP/CodeSniffer/Standards/Zend/ruleset.xml
in my Debian install after installing it with PEAR). Create another one based on it, but ignore the line-length bit:And set
--standard=/path/to/your/ruleset.xml
.Optionally, if you just want to up the char count before this is triggered, redefine the rule:
忽略消息 行超过 x 个字符 的另一种方法是使用
--exclude
标志来排除规则。为了找到要排除的规则名称,请在以下目录中找到相应的规则集:
vendor/squizlabs/php_codesniffer/src/Standards//ruleset.xml
规则名称将位于ref 节点:
速度更快,而且速度更快。比创建单独的规则集更方便。
An alternative way of ignoring the message Line exceeds x characters is to use the
--exclude
flag to exclude the rule.In order to find the rule name to exclude, find your corresponding ruleset in following directory:
vendor/squizlabs/php_codesniffer/src/Standards/<coding standard>/ruleset.xml
The rule name will be in the ref node:
It's quicker & less cumbersome than creating a separate ruleset.
查找文件 CodeSniffer/Standards/PEAR/ruleset.xml – 在 mac/linux 上您可以在终端中搜索:
找到 PEAR/ruleset.xml
或sudo find / -name "ruleset.xml"
然后您需要找到以下几行在ruleset.xml中:
<规则引用=“Generic.Files.LineLength”>
<属性>
<属性名称=“lineLimit”值=“85”/>
<属性名称=“absoluteLineLimit”值=“0”/>
只需将数字 85(行的最大长度)更改为您想要的即可。
请注意,phpc 的默认编码标准是 PEAR 标准。因此,您需要在此位置编辑ruleset.xml:CodeSniffer/Standards/PEAR/ruleset.xml
Find file CodeSniffer/Standards/PEAR/ruleset.xml – on mac/linux you can search in terminal:
locate PEAR/ruleset.xml
orsudo find / -name "ruleset.xml"
Then you need to find the following lines in the ruleset.xml:
<!-- Lines can be 85 chars long, but never show errors -->
<rule ref="Generic.Files.LineLength">
<properties>
<property name="lineLimit" value="85"/>
<property name="absoluteLineLimit" value="0"/>
</properties>
</rule>
Just change the number 85 (max length of the line) to what you want.
Notice that the phpc's default coding standard is the PEAR standard. So you need to edit ruleset.xml at this location: CodeSniffer/Standards/PEAR/ruleset.xml
如果您不想每次都使用参数输入整个命令
--standard=PSR2 --exclude=Generic.Files.LineLength app/
您可以创建文件phpcs.xml
> 在您的主目录中,并覆盖规则设置。然后您只需键入以下命令:
If you don't want to type every time whole command with parameters
--standard=PSR2 --exclude=Generic.Files.LineLength app/
you can create filephpcs.xml
in your main directory with overriden rule setting.You then need to type only following command: