sublime使用 sublime-phpcs 外掛
阿新 • • 發佈:2018-11-19
linux版本sublime使用 sublime-phpcs 外掛
# [瀏覽外掛]開啟外掛目錄
cd Sublime_Text/Packages/
# 在目錄裡面下載sublime-phpcs
git clone git://github.com/benmatselby/sublime-phpcs.git Phpcs
phar環境配置
官網
# 前提已經安裝php,下載 wget http://pear.php.net/go-pear.phar # 初始化 php go-pear.phar # 提示 Below is a suggested file layout for your new PEAR installation. To change individual locations, type the number in front of the directory. Type 'all' to change all of them or simply press Enter to accept these locations. 1. Installation base ($prefix) : /home/lxx/pear 2. Temporary directory for processing : /tmp/pear/install 3. Temporary directory for downloads : /tmp/pear/install 4. Binaries directory : /home/lxx/pear/bin 5. PHP code directory ($php_dir) : /home/lxx/pear/share/pear 6. Documentation directory : /home/lxx/pear/docs 7. Data directory : /home/lxx/pear/data 8. User-modifiable configuration files directory : /home/lxx/pear/cfg 9. Public Web Files directory : /home/lxx/pear/www 10. System manual pages directory : /home/lxx/pear/man 11. Tests directory : /home/lxx/pear/tests 12. Name of configuration file : /home/lxx/.pearrc 1-12, 'all' or Enter to continue: # 全回車,提示安裝到使用者lxx名目錄 /home/lxx/pear/share/pear # 修改了php.ini檔案 /etc/php/php.ini # 使用 /home/lxx/pear/bin/pear # 軟連結 sudo ln -s /home/lxx/pear/bin/pear /bin/pear # 可以直接使用 pear
phar外掛安裝
# 統一下載配置到/home/lxx/pear/bin/資料夾,國外原因,可能有點緩慢 # 1.PHP_CodeSniffer # info:http://pear.php.net/package/PHP_CodeSniffer/download # http://pear.php.net/manual/en/package.php.php-codesniffer.php # 說明:該包的作用是用指定的程式碼規範(預設使用PEAR規範,可指定使用PSR1,PSR2或自己制定的規範)來檢查程式碼是否符合規範。 pear install PHP_CodeSniffer-3.3.2 # 2.PHP Mess Detector (phpmd) # info:https://phpmd.org/documentation/index.html # 說明:檢查PHP程式碼存在的問題,潛在的BUG,定義但未使用的變數、方法、屬性等 cd /home/lxx/pear/bin/ wget -c http://static.phpmd.org/php/latest/phpmd.phar -O phpmd sudo chmod 777 phpmd # 3. PHP Coding Standards Fixer(php-cs-fixer) # 可以忽略 # info:https://github.com/FriendsOfPHP/PHP-CS-Fixer # 說明:該包可以修復PHP程式碼中的規範問題。 cd /home/lxx/pear/bin/ wget http://get.sensiolabs.org/php-cs-fixer.phar -O php-cs-fixer # wget https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v2.13.1/php-cs-fixer.phar -O php-cs-fixer sudo chmod 777 php-cs-fixer
配置
# 檢視php位置 which php # 其他外掛的位置我們下載到了 /home/lxx/pear/bin/ # 首選項Preferences -> 外掛設定Package Setting -> PHP Code Sniffer -> Setting – User對外掛進行配置 { "phpcs_php_path": "/usr/bin/php", "phpcs_executable_path": "/home/lxx/pear/bin/phpcs", "phpmd_executable_path": "/home/lxx/pear/bin/phpmd", "phpcbf_executable_path": "/home/lxx/pear/bin/phpcbf", "php_cs_fixer_executable_path": "/home/lxx/pear/bin/php-cs-fixer", // 開啟phpmd "phpmd_run": true } # phpcbf配置,使用PSR-2來格式化程式碼 "phpcs_additional_args": { "--standard": "PSR2", "-n": "" }, "phpcbf_additional_args": { "--standard": "PSR2", "-n": "" }, # 儲存時就格式化程式碼 "phpcbf_on_save": true
使用
# sublime-phpcs預設在儲存時執行檢查,自動彈窗
# 可根據提示自行修改,或點選右鍵,按照外掛選項對格式問題進行自動修復(phpmd檢測出的程式碼問題等需要手動修復)