win10上在sublime安装PHPcs(PHPcodesniffer)代码规范提示插件

首先按教程 http://blog.csdn.net/cyaspnet/article/details/51773331 装好phpcs和phpmd,需要先安装composer

composer global require "squizlabs/php_codesniffer=*"

安装后,在命令行输入 phpcs --version 显示版本号即为安装成功

如提示 shell_exec() has been disabled for security reasons ,请在 php.ini 禁用函数中 disable_functions 把 shell_exec 删除

composer global require phpmd/phpmd

安装后,在命令行输入 phpmd --version 显示版本号即为安装成功

然后在sublime 安装php code sniffer (网上教程说要去github下载其实是不需要的,sublime直接可以搜索到)

下面是我的配置

 

[javascript] view plain copy
 
  1. {  
  2.     // Example for:  
  3.     // - Windows 7  
  4.     // - With phpcs and php-cs-fixer support  
  5.   
  6.     // We want debugging on  
  7.     "show_debug"true,  
  8.   
  9.     // Only execute the plugin for php files  
  10.     "extensions_to_execute": ["php"],  
  11.   
  12.     // Do not execute for twig files  
  13.     "extensions_to_blacklist": ["twig.php"],  
  14.   
  15.     // Execute the sniffer on file save  
  16.     "phpcs_execute_on_save"true,  
  17.   
  18.     // Show the error list after save.  
  19.     "phpcs_show_errors_on_save"true,  
  20.   
  21.     // Show the errors in the gutter  
  22.     "phpcs_show_gutter_marks"true,  
  23.   
  24.     // Show outline for errors  
  25.     "phpcs_outline_for_errors"true,  
  26.   
  27.     // Show the errors in the status bar  
  28.     "phpcs_show_errors_in_status"true,  
  29.   
  30.     // Show the errors in the quick panel so you can then goto line  
  31.     "phpcs_show_quick_panel"true,  
  32.   
  33.     // Path to php on windows installation  
  34.     // This is needed as we cannot run phars on windows, so we run it through php  
  35.     "phpcs_php_prefix_path""D:\\xampp\\php\\php.exe",  
  36.   
  37.     // We want the fixer to be run through the php application  
  38.     "phpcs_commands_to_php_prefix": ["Fixer"],  
  39.   
  40.   
  41.     // PHP_CodeSniffer settings  
  42.     // Yes, run the phpcs command  
  43.     "phpcs_sniffer_run"true,  
  44.   
  45.     // And execute it on save  
  46.     "phpcs_command_on_save"true,  
  47.   
  48.     // This is the path to the bat file when we installed PHP_CodeSniffer  
  49.     "phpcs_executable_path""D:\\xampp\\php\\phpcs.bat",  
  50.   
  51.     // I want to run the PSR2 standard, and ignore warnings  
  52.     "phpcs_additional_args": {  
  53.         "--standard""PSR2",  
  54.         "-n"""  
  55.     },  
  56.   
  57.   
  58.     // PHP-CS-Fixer settings  
  59.     // Don't want to auto fix issue with php-cs-fixer  
  60.     "php_cs_fixer_on_save"false,  
  61.   
  62.     // Show the quick panel  
  63.     "php_cs_fixer_show_quick_panel"true,  
  64.   
  65.     // The fixer phar file is stored here:  
  66.     "php_cs_fixer_executable_path""D:\\xampp\\php\\php-cs-fixer.phar",  
  67.   
  68.     // Additional arguments, run all levels of fixing  
  69.     "php_cs_fixer_additional_args": {  
  70.     },  
  71.   
  72.   
  73.     // PHP Linter settings  
  74.     // Yes, lets lint the files  
  75.     "phpcs_linter_run"true,  
  76.   
  77.     // And execute that on each file when saved (php only as per extensions_to_execute)  
  78.     "phpcs_linter_command_on_save"true,  
  79.   
  80.     // Path to php  
  81.     "phpcs_php_path""D:\\xampp\\php\\php.exe",  
  82.   
  83.     // This is the regex format of the errors  
  84.     "phpcs_linter_regex""(?P<message>.*) on line (?P<line>\\d+)",  
  85.   
  86.   
  87.     // PHP Mess Detector settings  
  88.     // Not turning on the mess detector here  
  89.     "phpmd_run"false,  
  90.     "phpmd_command_on_save"false,  
  91.     "phpmd_executable_path""",  
  92.     "phpmd_additional_args": {  
  93.         "codesize,naming,unusedcode"""  
  94.     },  
  95.   
  96.     "phpcbf_executable_path""D:\\xampp\\php\\phpcbf.bat"  
  97. }  


按这个配好了就可以用了, 顺便说下, 不要装phpfmt这个插件,这个是不符合规范的。