PHPCS different ruleset for different directories
Asked Answered
O

2

6

I am currently working on cleaning up an existing codebase and one of the aspects involve using PHPCS. This is my phpcs.xml file at the moment:

<?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>

I'd like to modify it so that PSR-2 is applied to certain directories (e.g. foo/ and bar/) while the remaining directories are checked against PSR-1.

I found the <exclude-pattern> option in the manual that can be placed as child elements of the <rule> element but I need the opposite of that.

Opening answered 16/6, 2016 at 1:36 Comment(1)
I think you should ask for a feature request in issues of PHP_CodeSniffer. It will increase a chance to add it. Or you'll get a useful feedback there.Roodepoortmaraisburg
R
0

Create multiple configs and use --standard option to load them:

vendor/bin/phpcs source-to-check --standard first-settings.xml 
vendor/bin/phpcs another-to-check --standard second-settings.xml 
Roodepoortmaraisburg answered 28/10, 2017 at 12:1 Comment(0)
S
0
./vendor/bin/phpcs /project/path --standard=/other/path/phpcs.xml
Stich answered 21/2, 2022 at 22:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.