Php-cs-fixer: Ability to ignore some rules for some files

Created on 5 Jul 2018  路  8Comments  路  Source: FriendsOfPHP/PHP-CS-Fixer

The PHP version you are using ($ php -v):

=> 7.2.7

PHP CS Fixer version you are using ($ php-cs-fixer -V):

=> 2.12.1

The command you use to run PHP CS Fixer:

=> php-cs-fixer fix --dry-run -v

The configuration file you are using, if any:

https://github.com/symfony/symfony/blob/04b2c2db4f64174b9aca74f3cb60c84e55172807/.php_cs.dist

Due to having specific needs for some files only (for instance, we have a few files where we trigger unsilenced deprecation notices, because they are forwarding them from a sub-process and so should silence them or no based on the original one), we have to disable the fixing entirely for these files (as the only option we have today is excluding them in the fixer). It would be great if we could configure PHP-CS-Fixer to exclude only some specific fixers on such files.

kinfeature request

Most helpful comment

adding my two cents: would be nice to use inline comments to ignore/disable/enable particular/all rules as other linters do

All 8 comments

I think this kind of duplicates #3126.

hmm, indeed, this feature might solve things for us (I did not find this issue when searching for existing ones)

For me, this issue and the linked issue serve 2 different purposes:

For this issue, I would prefer eslint-style "disable these rules for this file" in the file itself over changing the actual config. Reasoning: it's just an exception to the config (maybe even to be fixed later), just like the example case given.

The linked issue would be a separate ruleset via config for example for template dirs (which is what I would use it for).

Well, in the case of Symfony, some of these files are fixture files to compare to the output of a code generator for instance. So we still prefer being able to ignore this rules from the config file, not from the file itself (as that would make the file itself unusable for its purpose)

And the linked issue is perfect for that indeed. Doesn't invalidate what I said though.

adding my two cents: would be nice to use inline comments to ignore/disable/enable particular/all rules as other linters do

:+1:

This feature is in ECS since very start: https://github.com/Symplify/EasyCodingStandard/blob/master/README.md#ignore-what-you-cant-fix

parameters:
    skip:
       SomeFixer:
          # relative path to file (you can copy this from error report)
          - 'src/Command/FixCommand.php'

          # or multiple files by path to match against "fnmatch()"
          - '*src/Command/*'

This can be easily transpiled to php in .php_cs file.

Feel free to reuse the code/idea to implement it here.

Any news?

Was this page helpful?
0 / 5 - 0 ratings