codesniffer - 使用 PHP CodeSniffer 检查排除文件夹的子目录
问题描述
我正在尝试配置我的phpcs.xml
(PHP CodeSniffer 配置文件),以便我可以将文件夹中的所有目录排除在检查之外,但我指定的目录除外。
对于熟悉 的人来说.gitignore
,等价物是这样的,因此“ButIncludeThisOne”包含在版本控制中。
/ignoreContentsWithin/*
!/ignoreContentsWithin/ButIncludeThisOne
我试过的
这是我的phpcs.xml
文件:
<?xml version="1.0"?>
<ruleset name="MyRuleset">
...
<!-- Exclude Plugin Folders. -->
<exclude-pattern>/cms/wp-content/plugins/*</exclude-pattern>
<!-- But Inspect My Plugin Folder. -->
<include-pattern>/cms/wp-content/plugins/myplugin/*</include-pattern>
</ruleset>
使用上面的示例,我可以指定 plugins 文件夹中的每个文件夹,但可以使用myplugin
,但这并不理想。(我必须记住从检查中排除任何新插件)
如果我删除该exclude-pattern
指令,文件myplugin
夹中的文件会被嗅探,所以我知道它正在工作。
解决方案
TLTR; 对于您的具体示例:
<exclude-pattern type="relative">^(?!cms/wp-content/plugins/myplugin).+</exclude-pattern>
您可以在那里使用正则表达式,但*
将用作.*
看看这个带有负前瞻的正则表达式。这里type="relative"
很重要。
<exclude-pattern type="relative">^(?!plugins/(arve-|advanced-re|edd-)).+</exclude-pattern>
推荐阅读
- awk - 匹配两个文件中的值并替换特定列中的值
- java - 每年动态创建表(hibernate+java+postgresql)
- python-2.7 - 添加命令行参数以读取所有图像以创建调色板
- python - 是否可以使用 GAN 仅填充图像的缺失部分而不是生成整个图像?
- oracle - 调用发送邮件程序后发生错误
- vba - 如何为word中存在的多个图像插入多个标题?例如图片下方的“图:1”
- airflow - dag 无法在气流中运行后,我的操作员仍在运行
- c++ - 在没有 memcpy() 的情况下通过引用分配数组值?
- angular - 如何在 ngFor 中显示一个简单 json 的所有键和值?
- c# - X Element 匹配时在表之间减去数据