2

I'm trying to set up PHPCS to run with PSR2 by default instead of having to specify it on each run.

I set the default with phpcs --config-set standard PSR2 When I check the configuration, it appears to be set:

$ phpcs --config-show
Using config file: /usr/bin/CodeSniffer.conf

standard: PSR2

When I actually run it on files, it runs as PEAR:

$ phpcs -v transarray.php 
Registering sniffs in the PEAR standard... DONE (28 sniffs registered)
Creating file list... DONE (1 files in queue)
Changing into directory /root
Processing transarray.php [PHP => 136 tokens in 26 lines]... DONE in 2ms  (11 errors, 0 warnings)
...

If I run phpcs --standard=PSR2 ... it works correctly, but I would rather not have to include that every single time I run it.

The code errors reported match the standards in use.

user984869
  • 432
  • 2
  • 8

1 Answers1

2

According to the documentation you have to use default_standard as configuration key. So the command must be:

phpcs --config-set default_standard PSR2

common sense
  • 3,775
  • 6
  • 22
  • 31
  • You've earned your username! I can't believe the number of people who missed that. Thanks you so much. I'm about 10 ways into this and have been looking through source code to figure it out. I feel dumb, but I can probably contribute some other fixes to PHPCS now that I've been through it so much. – user984869 Jan 15 '19 at 00:50
  • Thank you! Glad to help. – common sense Jan 15 '19 at 09:53