【问题标题】:Sublime Text 3 Phpcs not working on Windows7Sublime Text 3 Phpcs 在 Windows7 上不起作用
【发布时间】:2014-03-31 06:41:11
【问题描述】:

我已经在我的 Sublime Text3 中使用 @install 包安装了 PHPCS。我可以看到 Tools->PHP Code Sniffer:Sniff this file 命令,但是当我选择“Sniff this file”命令时没有任何反应。 这是我的 Prefrences->Package Settings->PHP Code Sniffer->Settings default

{
// Plugin settings

// Turn the debug output on/off
"show_debug": false,

// Which file types (file extensions), do you want the plugin to
// execute for
"extensions_to_execute": ["php"],

// Do we need to blacklist any sub extensions from extensions_to_execute
// An example would be ["twig.php"]
"extensions_to_blacklist": [],

// 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,

// The path to the php executable.
// Needed for windows, or anyone who doesn't/can't make phars
// executable. Avoid setting this if at all possible
"phpcs_php_prefix_path": "G:\\xampp\\php\\php.exe",

// Options include:
// - Sniffer
// - Fixer
// - Mess Detector
//
// This will prepend the application with the path to php
// Needed for windows, or anyone who doesn't/can't make phars
// executable. Avoid setting this if at all possible
"phpcs_commands_to_php_prefix": ["Fixer"],


// PHP_CodeSniffer settings

// Do you want to run the phpcs checker?
"phpcs_sniffer_run": true,

// Execute the sniffer on file save
"phpcs_command_on_save": true,

// It seems python/sublime cannot always find the phpcs application
// If empty, then use PATH version of phpcs, else use the set value
"phpcs_executable_path":  "G:\\xampp\\php\\phpcs.bat",

// Additional arguments you can specify into the application
//
// Example:
// {
//     "--standard": "PEAR",
//     "-n"
// }
"phpcs_additional_args": {
    "--standard": "PEAR",
    "-n": ""
},



// PHP-CS-Fixer settings

// Fix the issues on save
"php_cs_fixer_on_save": false,

// Show the quick panel
"php_cs_fixer_show_quick_panel": false,

// Path to where you have the php-cs-fixer installed
"php_cs_fixer_executable_path":  "G:\\xampp\\php\\php-cs-fixer.phar",

// Additional arguments you can specify into the application
//
// Example:
// {
//     "--level": "all"
// }
"php_cs_fixer_additional_args": {
    "--level": "all"
},



// PHP Linter settings

// Are we going to run php -l over the file?
"phpcs_linter_run": true,

// Execute the linter on file save
"phpcs_linter_command_on_save": true,

// It seems python/sublime cannot always find the php application
// If empty, then use PATH version of php, else use the set value
"phpcs_php_path": "G:\\xampp\\php\\php.exe",

// What is the regex for the linter? Has to provide a named match for 'message' and 'line'
"phpcs_linter_regex": "(?P<message>.*) on line (?P<line>\\d+)",



// PHP Mess Detector settings

// Execute phpmd
"phpmd_run": false,

// Execute the phpmd on file save
"phpmd_command_on_save": true,

// It seems python/sublime cannot always find the phpmd application
// If empty, then use PATH version of phpmd, else use the set value
"phpmd_executable_path": "",

// Additional arguments you can specify into the application
//
// Example:
// {
//     "codesize,unusedcode"
// }
"phpmd_additional_args": {
    "codesize,unusedcode,naming": ""
},


// PHP Scheck settings

// Execute scheck
"scheck_run": false,

// Execute the scheck on file save
"scheck_command_on_save": false,

// It seems python/sublime cannot always find the scheck application
// If empty, then use PATH version of scheck, else use the set value
"scheck_executable_path": "",

// Additional arguments you can specify into the application
//
//Example:
//{
//  "-php_stdlib" : "/path/to/pfff",
//  "-strict" : ""
//}
"scheck_additional_args": {
    "-strict" : ""
}

}

此外,我可以使用phpcs -i 命令查看 PHPCS 详细信息,并且可以使用 CLI 嗅探我的代码文件,但 sublime 中没有显示任何内容:(

【问题讨论】:

  • 你可以试试 SublimeLinter 和 SublimeLinter-phpcs 看看是否有效
  • 控制台中有错误信息吗?
  • 你有解决这个问题的方法吗?

标签: php sublimetext3 codesniffer


【解决方案1】:

在 Windows 7 Wamp Server 环境中设置,我通过确保解决了这个问题

"phpcs_commands_to_php_prefix": ["Fixer"]

曾经

"phpcs_commands_to_php_prefix": []

即“尽可能避免设置”

还有:

"phpcs_php_prefix_path": "G:\\xampp\\php\\php.exe"

可以

"phpcs_php_prefix_path": "G:\\xampp\\php\\"

【讨论】:

    【解决方案2】:

    以防万一您忘记使用

    开始您的文件
    <?php
    

    而不仅仅是

    <?
    

    如果你跳过了这个,那么 phpcs 将无法正常工作。

    【讨论】:

      【解决方案3】:

      尝试将路径 phpcs_php_prefix_path 值更改为“G:\xampp\php\”,删除 php.exe。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-09-26
        • 1970-01-01
        • 2018-11-16
        • 2013-08-31
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多