简体   繁体   English

如何从 PHP 代码嗅探器检查 in.phpcs.xml 中排除除某些目录之外的所有内容?

[英]How to exclude everything except some directories from PHP Code Sniffer inspections in .phpcs.xml?

I would like to exclude everything except some directories from PHP Code Sniffer inspection in my project.我想在我的项目中从PHP Code Sniffer检查中排除除某些目录之外的所有内容。 Something similar like git repo exclusions with.gitignore类似于 git 回购排除与.gitignore

I had the idea that regex with negative lookahead could be used with <exclude-pattern >.我的想法是带有负前瞻的regex可以与<exclude-pattern > 一起使用。 I tried:我试过了:

<exclude-pattern>^(?!wp-content\/plugins\/customplugin\/*$|wp-content\/themes\/customtheme\/*$).+</exclude-pattern>

Consequently, I expected PHPCS to only scan the wp-content/plugins/customplugin/ and wp-content/themes/customtheme/ .因此,我希望 PHPCS 只扫描wp-content/plugins/customplugin/wp-content/themes/customtheme/ Unfortunately it doesn't work:不幸的是,它不起作用:

Registering sniffs in the Project standard... DONE (138 sniffs registered)
Creating file list... DONE (0 files in queue)

How to achieve this in the right way?如何以正确的方式实现这一目标?

To achieve the intended goal, we must modify the regular expression:为了达到预期的目的,我们必须修改正则表达式:

<exclude-pattern>^(?!.*\/wp-content\/plugins\/customplugin|.*\/wp-content\/themes\/customtheme).*</exclude-pattern>

Note that it may be possible to resolve this issue in a different way in the future thanks to this ticket in the CodeSniffer repository请注意,由于 CodeSniffer 存储库中的票证,将来可能以不同的方式解决此问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM