Sublime Text 3如何設定php語法錯誤提示外掛?

2020-07-16 10:06:23

Sublime Text 3設定php語法錯誤提示外掛的方法:首先下載sniffer外掛安裝包;然後下載外掛並放到php.exe安裝目錄裡;接著設定都改成本地環境下的php安裝路徑;最後儲存,重新啟動Sublime Text 3即可。

Sublime Text 3設定php語法錯誤提示外掛的方法:

第一步:下載php code sniffer外掛安裝包

解壓安裝包得到sublime-phpcs-master,把sublime-phpcs-master資料夾放到sublime安裝目錄下的Data/Packages/目錄下;

重新啟動sublime, 開啟Sublime Text 3->Preferences->Package Settings -> Php Code Sniffer 證明外掛安裝成功;

第二步:下載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 安裝目錄;

第五步:解壓開啟,在子檔案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路徑

設定都改成你本地環境下的php安裝路徑,儲存,重新啟動Sublime Text 3

{
// 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": "C:wampbinphpphp5.4.12php.exe",
// This is the path to the bat file when we installed PHP_CodeSniffer
"phpcs_executable_path": "C:wampbinphpphp5.4.12phpcs.bat",
// 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": "C:wampbinphpphp5.4.12php-cs-fixer.phar",
// 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": "C:wampbinphpphp5.4.12php.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": {}
}

重新啟動Sublime Text 3,開啟php程式,語法錯誤提示如下圖:

c3321977ed02d056bc57470c69b3588.png

以上就是Sublime Text 3如何設定php語法錯誤提示外掛?的詳細內容,更多請關注TW511.COM其它相關文章!