PHP CodeSniffer

Code/PHP 2021. 3. 12. 18:32

PHP_CodeSniffer  - PHP, JavaScript , CSS 파일의 코드 규약 오류 감지, 자동 수정 툴

 

 

https://github.com/squizlabs/PHP_CodeSniffer - 8.4k

    - v3.5.8 ,  2020.10



composer global require "squizlabs/php_codesniffer"

 

    - 경로 추가

%APPDATA%\Composer\vendor\bin

 

    - 코드 검사

phpcs

 

    - 코드 포맷, 오류 수정

phpbcf



//--------------------------

< 설정 >

https://scrutinizer-ci.com/docs/tools/php/code-sniffer/

 

https://github.com/squizlabs/PHP_CodeSniffer/wiki/Configuration-Options

 

    - 설정 파일

phpcs.xml




//---------------------------------------

- PHP CodeSniffer Coding Standard Rule 추가 설치

 

- WordPress

 WordPress /WordPress-Coding-Standards 

https://github.com/WordPress/WordPress-Coding-Standards - 2k

 

https://medium.com/@mcnamee/phpcs-code-linting-for-wordpress-c340199364c6

 

composer global require wp-coding-standards/wpcs

 

/*

phpcs --config-set installed_paths ~/.composer/vendor/wp-coding-standards/wpcs

    - ~/.composer/vendor/squizlabs/php_codesniffer/CodeSniffer.conf 파일 수정됨

<?php

 $phpCodeSnifferConfig = array (

  'installed_paths' => '~/.composer/vendor/wp-coding-standards/wpcs', <== 상대경로로 수정 필요

'installed_paths' => '../../wp-coding-standards/wpcs',

*/

 

composer global require dealerdirect/phpcodesniffer-composer-installer

    - CodeSniffer.conf 파일이 제대로 수정됨, 모든 플러그인 추가됨

 

phpcs -i

The installed coding standards are MySource, PEAR, PSR1, PSR12, PSR2, Squiz, Zend, Drupal, DrupalPractice, VariableAnalysis, WordPress, WordPress-Core, WordPress-Docs and WordPress-Extra

 

phpcs --standard=WordPress source.php



//--------------

- Drupal

https://git.drupalcode.org/project/coder

https://www.drupal.org/docs/contributed-modules/code-review-module/installing-coder-sniffer

 

composer global require drupal/coder

 

/*

phpcs --config-set installed_paths ~/.composer/vendor/drupal/coder/coder_sniffer

    - ~/.composer/vendor/squizlabs/php_codesniffer/CodeSniffer.conf 파일 수정됨

<?php

 $phpCodeSnifferConfig = array (

  'installed_paths' => '~/.composer/vendor/drupal/coder/coder_sniffer',, <== 상대경로로 수정 필요

'installed_paths' => '../../drupal/coder/coder_sniffer',

*/

 

composer global require dealerdirect/phpcodesniffer-composer-installer

    - CodeSniffer.conf 파일이 제대로 수정됨, 모든 플러그인 추가됨

 

phpcs -i



phpcs --standard=Drupal mix.php





//---------------------------------------------------------------

//---------------------------------------------------------------

< VS Code Extension >



* phpcs - ikappas.phpcs

https://marketplace.visualstudio.com/items?itemName=ikappas.phpcs - 981,670 

    -   1.0.5 , 2018. 3  <=== 업데이트 오래됨

 

https://github.com/ikappas/vscode-phpcs - 46




//---------------------------------------------------------------

* PHP Sniffer - wongjn.php-sniffer

https://marketplace.visualstudio.com/items?itemName=wongjn.php-sniffer - 63,840

    -   1.3.0   , 2020. 11



composer global require squizlabs/php_codesniffer





//---------------------------------------------------------------

* PHP Sniffer & Beautifier

    - valeryanm.vscode-phpsab

https://marketplace.visualstudio.com/items?itemName=ValeryanM.vscode-phpsab - 40,973

    -   v0.0.11 , 2020. 8.





//---------------------------------------------------------------

* php-code-sniffer

    - etubaro.php-code-sniffer

 

https://marketplace.visualstudio.com/items?itemName=ETubaro.php-code-sniffer - 539

    -   1.0.6   , 2020. 11.




반응형
Posted by codens