squizlabs / PHP_CodeSniffer

PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.
BSD 3-Clause "New" or "Revised" License
10.67k stars 1.48k forks source link

Is it possible to have different configuration values for different files? #2699

Closed benignant closed 4 years ago

benignant commented 4 years ago

I'm using PHPCompatibility and I'd like to have different configuration values for different files.

For some files I want the following configuration:

<config name="testVersion" value="5.5-"/>

And for other files:

<config name="testVersion" value="5.2-"/>

I'd like to do this from my phpcs.xml file. Is this possible?

jrfnl commented 4 years ago

Have a look at #1821 and the follow-up #2197.

gsherwood commented 4 years ago

I don't think the issue is that the config value is being overridden. It sounds like @benignant wants to have some files checked as PHP 5.5 and some as PHP 5.2.

This is not possible within a ruleset.xml file. The value you define there is set before the run begins, then that value is used throughout the run.

If you want to apply different values to different files or directories, you'd need to do 2 different runs and so have 2 different rulesets - one for PHP 5.5 and one for 5.2.

Unless PHPCompatibility has a specific feature for this. You could ask over there to be sure, but I don't think a core PHPCS feature is going to help you here.

benignant commented 4 years ago

Got it, thanks. I'm using some editor tooling which automatically runs phpcs with my phpcs.xml file, so this solution won't work for that. But at least this will work with a Composer script.