【问题标题】:PHPCS different ruleset for different directoriesPHPCS针对不同目录的不同规则集
【发布时间】:2022-02-22 06:20:43
【问题描述】:

我目前正在清理现有的代码库,其中一个方面涉及使用 PHPCS。这是我目前的phpcs.xml 文件:

<?xml version='1.0'?>
<ruleset name='MyApplication'>
    <arg name='encoding' value='utf-8'/>
    <arg name='extensions' value='php'/>
    <arg name='warning-severity' value='0'/>
    <arg name='colors'/>
    <arg value='p'/>

    <exclude-pattern>vendor/*</exclude-pattern>
    <exclude-pattern>node_modules/*</exclude-pattern>

    <rule ref='PSR1'></rule>
</ruleset>

我想对其进行修改,以便将 PSR-2 应用于某些目录(例如 foo/bar/),同时对照 PSR-1 检查其余目录。

我在手册中找到了&lt;exclude-pattern&gt; 选项,它可以作为&lt;rule&gt; 元素的子元素放置,但我需要相反的。

【问题讨论】:

标签: php phpcs


【解决方案1】:

创建多个配置并使用--standard 选项加载它们:

vendor/bin/phpcs source-to-check --standard first-settings.xml 
vendor/bin/phpcs another-to-check --standard second-settings.xml 

【讨论】:

    【解决方案2】:
    ./vendor/bin/phpcs /project/path --standard=/other/path/phpcs.xml
    

    【讨论】:

      猜你喜欢
      • 2020-01-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-07
      • 1970-01-01
      相关资源
      最近更新 更多