当PHP_CodeSniffer分析php文件时,可能会忽略其中的某些代码部分
发布于 2010-11-30 02:29:44
是的,可以使用@codingStandardsIgnoreStart和@codingStandardsIgnoreEnd注释
<?php
some_code();
// @codingStandardsIgnoreStart
this_will_be_ignored();
// @codingStandardsIgnoreEnd
some_other_code();发布于 2015-06-10 19:09:00
您可以使用组合:@codingStandardsIgnoreStart和@codingStandardsIgnoreEnd,也可以使用@codingStandardsIgnoreLine。
示例:
<?php
command1();
// @codingStandardsIgnoreStart
command2(); // this line will be ignored by Codesniffer
command3(); // this one too
command4(); // this one too
// @codingStandardsIgnoreEnd
command6();
// @codingStandardsIgnoreLine
command7(); // this line will be ignored by Codesniffer发布于 2018-10-19 03:56:51
在3.2.0版本之前,PHP_CodeSniffer使用不同的语法忽略文件中的代码部分。请参阅 和 答案。旧语法将在版本4.0中删除
PHP_CodeSniffer现在使用// phpcs:disable和// phpcs:enable注释来忽略文件的某些部分,使用// phpcs:ignore来忽略一行。
现在,还可以仅禁用或启用特定错误消息代码、嗅探、嗅探类别或整个编码标准。您应该在注释后指定它们。如果需要,您可以添加注释,解释使用--分隔符禁用和重新启用嗅探的原因。
<?php
/* Example: Ignoring parts of file for all sniffs */
$xmlPackage = new XMLPackage;
// phpcs:disable
$xmlPackage['error_code'] = get_default_error_code_value();
$xmlPackage->send();
// phpcs:enable
/* Example: Ignoring parts of file for only specific sniffs */
// phpcs:disable Generic.Commenting.Todo.Found
$xmlPackage = new XMLPackage;
$xmlPackage['error_code'] = get_default_error_code_value();
// TODO: Add an error message here.
$xmlPackage->send();
// phpcs:enable
/* Example: Ignoring next line */
// phpcs:ignore
$foo = [1,2,3];
bar($foo, false);
/* Example: Ignoring current line */
$foo = [1,2,3]; // phpcs:ignore
bar($foo, false);
/* Example: Ignoring one line for only specific sniffs */
// phpcs:ignore Squiz.Arrays.ArrayDeclaration.SingleLineNotAllowed
$foo = [1,2,3];
bar($foo, false);
/* Example: Optional note */
// phpcs:disable PEAR,Squiz.Arrays -- this isn't our code
$foo = [1,2,3];
bar($foo,true);
// phpcs:enable PEAR.Functions.FunctionCallSignature -- check function calls again
bar($foo,false);
// phpcs:enable -- this is out code again, so turn everything back on有关详细信息,请参阅PHP_CodeSniffer's documentation。
https://stackoverflow.com/questions/4306304
复制相似问题