sublime text 3 phpcs

来源:互联网 发布:php 整数变小数 编辑:程序博客网 时间:2024/06/05 21:42

这里写链接内容

第一步:下载php code sniffer插件安装包 地址 https://github.com/benmatselby/sublime-phpcs;
解压安装包得到sublime-phpcs-master,把sublime-phpcs-master文件夹放到sublime安装目录下的Packages/目录下;重启sublime, 打开Sublime Text 3->Preferences->Package Settings -> Php Code Sniffer 证明插件安装成功;
注意:不要从package controller上安装,后面报nicodedecodeerror错误,改不了源码。
pagekages目录可以在sublime中打开一个配置文件找到,如图:
这里写图片描述

第二步:下载php-cs-fixer.phar 地址 http://cs.sensiolabs.org/get/php-cs-fixer.phar ;

第三步:把php-cs-fixer.phar 放到你的 php.exe 安装目录 (例如(mine is C:/WAMP/php/php.exe));

第四步:下载 http://download.pear.php.net/package/PHP_CodeSniffer-1.5.0RC4.tgz,解压,然后找到scripts目录下的phpcs.bat,放到php.exe 安装目录;
注意:在这一步中,我没有成功,解决方法参考这里写链接内容

第五步:解压打开 第一步下载的php code sniffer安装包,在子文件example-settings下有个文件
windows-7-phpcs-fixer-linter.example 就是Sublime Text 3 在windows7配置 PHPCS 的样例,还有一个nix-all-commands.example是在linux/unix环境下的配置样例

第六步:以下就是windows-7-phpcs-fixer-linter.example的配置内容,打开你的Sublime Text 3->Preferences->Package Settings -> Php Code Sniffer -> Settings - User ,复制 windows-7-phpcs-fixer-linter.example 的内容到配置文件phpcs.sublime-settings,然后修改对应的php.exe路径

{    // Example for:    // - Windows 8.1    // - With phpcs and php-cs-fixer support    // - You have to change "YOUR_USERNAME_HERE" strings.    // - Notice: This uses phpcs which is installed    // -         using composer not xampp.    // -         Be sure to install phpcs using composer.    // We want debugging on    "show_debug": true,    // Only execute the plugin for php files    "extensions_to_execute": ["php"],    // Do not execute for twig files    "extensions_to_blacklist": ["twig.php"],    // Execute the sniffer on file save    "phpcs_execute_on_save": true,    // Show the error list after save.    "phpcs_show_errors_on_save": true,    // Show the errors in the gutter    "phpcs_show_gutter_marks": true,    // Show outline for errors    "phpcs_outline_for_errors": true,    // Show the errors in the status bar    "phpcs_show_errors_in_status": true,    // Show the errors in the quick panel so you can then goto line    "phpcs_show_quick_panel": true,    // Path to php on windows installation    // This is needed as we cannot run phars on windows, so we run it through php    "phpcs_php_prefix_path": "D:\\wamp\\bin\\php\\php7.0\\php.exe",    // We want the fixer to be run through the php application    "phpcs_commands_to_php_prefix": ["Fixer"],    // PHP_CodeSniffer settings    // Yes, run the phpcs command    "phpcs_sniffer_run": true,    // And execute it on save    "phpcs_command_on_save": true,    // This is the path to the bat file when we installed PHP_CodeSniffer    "phpcs_executable_path": "D:\\wamp\\bin\\php\\php7.0\\PHP_CodeSniffer-1.5.0RC4\\scripts\\phpcs.bat",    // I want to run the PSR2 standard, and ignore warnings    "phpcs_additional_args": {        "--standard": "PSR2",        "-n": ""    },    // PHP-CS-Fixer settings    // Don't want to auto fix issue with php-cs-fixer    "php_cs_fixer_on_save": false,    // Show the quick panel    "php_cs_fixer_show_quick_panel": true,    // The fixer phar file is stored here:    "php_cs_fixer_executable_path": "D:\\wamp\\bin\\php\\php7.0\\php-cs-fixer.phar",    // Additional arguments, run all levels of fixing    "php_cs_fixer_additional_args": {    },    // PHP Linter settings    // Yes, lets lint the files    "phpcs_linter_run": true,    // And execute that on each file when saved (php only as per extensions_to_execute)    "phpcs_linter_command_on_save": true,    // Path to php    "phpcs_php_path": "D:\\wamp\\bin\\php\\php7.0\\php.exe",    // This is the regex format of the errors    "phpcs_linter_regex": "(?P<message>.*) on line (?P<line>\\d+)",    // PHP Mess Detector settings    // Not turning on the mess detector here    "phpmd_run": false,    "phpmd_command_on_save": false,    "phpmd_executable_path": "",    "phpmd_additional_args": {}}