4

I want to know my current PHPCS standard in Visual Studio

e.g:

 {
     "phpcs.standard": "PSR2"
 }

how to set it is given in the documentation

phpcs --config-set default_standard value

lokender singh
  • 829
  • 9
  • 18

2 Answers2

4

when you config

phpcs --config-set default_standard value

a message will show up like:

Using config file: /home/yourpc/.composer/vendor/squizlabs/php_codesniffer/CodeSniffer.conf

so, the configuration will be storage in:

/home/yourpc/.composer/vendor/squizlabs/php_codesniffer/CodeSniffer.conf
mr.Thi
  • 41
  • 3
  • 1
    If you want to use the local `phpcs` instead of the global `phpcs`, run `vendor/bin/phpcs --confi-set` instead – Flimm Jul 14 '22 at 13:55
1

You can run phpcs with -i to print your installed standards:

~$ phpcs -i
The installed coding standards are PEAR, Zend, PSR2, MySource, Squiz, PSR1, PSR12, Universal, NormalizedArrays, PHPCS23Utils, PHPCSUtils, NoGetCurrentUser, VariableAnalysis, WordPress, WordPress-Extra, WordPress-Docs, WordPress-Core, IsolatedTests, WordPress-Core, WordPress and WordPress-Docs

You can get information on where these standards are being pulled from, as well as which configuration file is in use by calling phpcs with the --config-show flag:

~$ phpcs --config-show
Using config file: /Users/pz/.composer/vendor/squizlabs/php_codesniffer/CodeSniffer.conf

installed_paths: /Users/pz/.composer/vendor/phpcsstandards/phpcsextra,/Users/pz/.composer/vendor/phpcsstandards/phpcsutils,/Users/pz/.composer/vendor/sirbrillig/phpcs-no-get-current-user,/Users/pz/.composer/vendor/sirbrillig/phpcs-variable-analysis,/Users/pz/.composer/vendor/wp-coding-standards/wpcs,/Users/pz/Code/wpcom/bin/metrics/shared/phpcs-coding-standards/IsolatedTests,/Users/pz/Code/wpcom/bin/metrics/shared/phpcs-coding-standards/WordPress-Coding-Standards/WordPress-Core,/Users/pz/Code/wpcom/bin/metrics/shared/phpcs-coding-standards/WordPress-Coding-Standards/WordPress,/Users/pz/Code/wpcom/bin/metrics/shared/phpcs-coding-standards/WordPress-Coding-Standards/WordPress-Docs

It's worth mentioning that if you have a phpcs.xml file in your project phpcs will try to discover and use that by default. If you want to run it with a specific standard, you will use the --standard flag:

phpcs --standard=Pear <option filepath etc>

The usage page on the repository is quite comprehensive.

Patrick.SE
  • 4,444
  • 5
  • 34
  • 44