如何在自定义phpcs.xml规则集中排除特定规则?

时间:2018-12-19 12:42:39

标签: coding-style phpcs

我正在寻找一种自动化编码标准的方法,因此我决定在我们的phpcs.xml文件中使用 ['layer[1]=level[' 'layer[2]=level[' 'layer[3]=level[' 'layer[4]=level[' 'layer[5]=level[' 'layer[6]=level[' 'layer[7]=level[' ... '1].' '1].' '2].' '2].' '2].' '3].' '3].' '3].' '4].' '4].' '4].' ... 'x1' 'x2' 'M' 'x1' 'x2' 'M' 'x1' 'x2' 'M' 'x1' 'x2' 'M' 'x1' 'x2' 'M' ...] 。不幸的是,我们遇到了错误报告问题:

SlevomatCodingStandard.TypeHints.TypeHintDeclaration

我只想为方法添加严格的返回类型,但对于我们正在使用 38 | ERROR | [ ] @var annotation of property | | \VC4A\ConvertUploadsToS3::$missing_local_files | | does not specify type hint for its items. 45 | ERROR | [ ] @var annotation of property | | \VC4A\ConvertUploadsToS3::$missing_s3_files does | | not specify type hint for its items. 52 | ERROR | [ ] @var annotation of property | | \VC4A\ConvertUploadsToS3::$updated_s3_links does | | not specify type hint for its items. 66 | ERROR | [ ] @var annotation of property | | \VC4A\ConvertUploadsToS3::$s3_settings does not | | specify type hint for its items. 112 | ERROR | [ ] Method \VC4A\ConvertUploadsToS3::setup_crons() | | does not have return type hint nor @return | | annotation for its return value. 149 | ERROR | [ ] @return annotation of method | | \VC4A\ConvertUploadsToS3::get_cron_actions() does | | not specify type hint for items of its traversable | | return value. 202 | ERROR | [ ] @return annotation of method | | \VC4A\ConvertUploadsToS3::get_cron_intervals() | | does not specify type hint for items of its | | traversable return value. 266 | ERROR | [ ] @param annotation of method | | \VC4A\ConvertUploadsToS3::error_reporting() does | | not specify type hint for items of its traversable | | parameter $uploads. 334 | ERROR | [ ] @param annotation of method | | \VC4A\ConvertUploadsToS3::update_s3_link() does | | not specify type hint for items of its traversable | | parameter $upload. 336 | ERROR | [x] Method \VC4A\ConvertUploadsToS3::update_s3_link() | | does not have void return type hint. 标准的DocBlocks,则要添加严格的返回类型。

是否有一种方法可以禁用除最后一个错误以外的其余错误?

我尝试过的是这个

WordPress-Docs

显然这没有任何作用。有什么建议么 ?还是仅添加特定规则的正确方法是什么?

或者有可能以其他方式做到这一点?只需在规则集中添加特定规则,而无需修改代码库?

1 个答案:

答案 0 :(得分:0)

显然,我应该使用常量值而不是类数据成员名称:

<!-- Strict type return for methods --> <rule ref="SlevomatCodingStandard.TypeHints.TypeHintDeclaration"> <exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversableParameterTypeHintSpecification"/> <exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversablePropertyTypeHintSpecification"/> <exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversableReturnTypeHintSpecification"/> </rule>

来源: https://github.com/slevomat/coding-standard/issues/570#issuecomment-448647567