benmatselby / sublime-phpcs

🔍 PHP CodeSniffer, PHP Coding Standard Fixer, Linter, and Mess Detector Support for Sublime Text
Other
813 stars 126 forks source link

php-cs-fixer not working #52

Closed TNAJanssen closed 11 years ago

TNAJanssen commented 11 years ago

Nevermind just found it! It says i'm using to much arguments(didn't change anything about it!)

The problem is spaces in directory or file name! can you fix this in python?

benmatselby commented 11 years ago

Hi there..

Which version of php-cs-fixer are you using? I've got the latest version and a fresh install of this plugin and when looking in the console I can see:

[Phpcs] /usr/local/bin/php-cs-fixer.phar fix /Users/bselby/path/to/file.php --verbose --level=all
TNAJanssen commented 11 years ago

I'm using version 0.2, it did work before! it suddenly stopped working. This is what in my console:

php-cs-fixer fix /Users/AJanssen/Dropbox/Easy Cloud/Projecten/Zend Modules/ACL/src/Service/Permission.php --verbose --level=all

When i run this manual it says [RuntimeException]
Too many arguments.

When i escape the spaces like this: php-cs-fixer fix /Users/AJanssen/Dropbox/Easy\ Cloud/Projecten/Zend\ Modules/ACL/src/Service/Permission.php --verbose --level=all it works!

TNAJanssen commented 11 years ago

i do have an error under that command: [Phpcs] ERROR: option "- " not known. Usage: phpcs [-nwlsaepvi] [-d key[=value]] [--report=] [--report-file=] [--report-=] ... [--report-width=] [--generator=] [--tab-width=] [--severity=] [--error-severity=] [--warning-severity=] [--config-set key value] [--config-delete key] [--config-show] [--standard=] [--sniffs=] [--encoding=] [--extensions=] [--ignore=] ... -n Do not print warnings (shortcut for --warning-severity=0) -w Print both warnings and errors (on by default) -l Local directory only, no recursion -s Show sniff codes in all reports -a Run interactively -e Explain a standard by showing the sniffs it includes -p Show progress of the run -v[v][v] Print verbose output -i Show a list of installed coding standards -d Set the [key] php.ini value to [value] or [true] if value is omitted --help Print this help message --version Print version information

One or more files and/or directories to check A comma separated list of file extensions to check (only valid if checking a directory) A comma separated list of patterns to ignore files and directories The encoding of the files being checked (default is iso-8859-1) A comma separated list of sniff codes to limit the check to (all sniffs must be part of the specified standard) The minimum severity required to display an error or warning The name or path of the coding standard to use The number of spaces each tab represents The name of a doc generator to use (forces doc generation instead of checking) Print either the "full", "xml", "checkstyle", "csv", "emacs" "source", "summary", "svnblame", "gitblame", "hgblame" or "notifysend" report (the "full" report is printed by default) Write the report to the specified file path How many columns wide screen reports should be printed
benmatselby commented 11 years ago

So is the bug here that you have spaces in the paths and the plugin cannot handle that?

TNAJanssen commented 11 years ago

It seems like it, when i try it in terminal it works perfectly! the phpcs on the other hand does work! although the error from above! Here is the complete console output when i try to save:

[Phpcs] /Applications/MAMP/bin/php/php5.4.4/bin/phpcs -l -d display_errors=On /Users/AJanssen/Dropbox/Easy Cloud/Projecten/Zend Modules/ACL/src/Service/Permission.php [Phpcs] php-cs-fixer fix /Users/AJanssen/Dropbox/Easy Cloud/Projecten/Zend Modules/ACL/src/Service/Permission.php --verbose --level=all [Phpcs] [Phpcs] ERROR: option "- " not known.

Usage: phpcs [-nwlsaepvi] [-d key[=value]] [--report=] [--report-file=] [--report-=] ... [--report-width=] [--generator=] [--tab-width=] [--severity=] [--error-severity=] [--warning-severity=] [--config-set key value] [--config-delete key] [--config-show] [--standard=] [--sniffs=] [--encoding=] [--extensions=] [--ignore=] ... -n Do not print warnings (shortcut for --warning-severity=0) -w Print both warnings and errors (on by default) -l Local directory only, no recursion -s Show sniff codes in all reports -a Run interactively -e Explain a standard by showing the sniffs it includes -p Show progress of the run -v[v][v] Print verbose output -i Show a list of installed coding standards -d Set the [key] php.ini value to [value] or [true] if value is omitted --help Print this help message --version Print version information

One or more files and/or directories to check A comma separated list of file extensions to check (only valid if checking a directory) A comma separated list of patterns to ignore files and directories The encoding of the files being checked (default is iso-8859-1) A comma separated list of sniff codes to limit the check to (all sniffs must be part of the specified standard) The minimum severity required to display an error or warning The name or path of the coding standard to use The number of spaces each tab represents The name of a doc generator to use (forces doc generation instead of checking) Print either the "full", "xml", "checkstyle", "csv", "emacs" "source", "summary", "svnblame", "gitblame", "hgblame" or "notifysend" report (the "full" report is printed by default) Write the report to the specified file path How many columns wide screen reports should be printed [Phpcs] /Applications/MAMP/bin/php/php5.4.4/bin/phpcs --report=checkstyle --warning-severity=0 --standard=PEAR /Users/AJanssen/Dropbox/Easy Cloud/Projecten/Zend Modules/ACL/src/Service/Permission.php [Phpcs] [Phpcs] Linter found 0 errors [Phpcs] Sniffer found 14 errors [Phpcs] MessDetector found 0 errors And when i try to php-cs-fixer from the menu: [Phpcs] php-cs-fixer fix /Users/AJanssen/Dropbox/Easy Cloud/Projecten/Zend Modules/ACL/src/Service/Permission.php --verbose --level=all [Phpcs]
benmatselby commented 11 years ago

OK two things.

I assume there are errors that php-cs-fixer would find in your file, and secondly, I think the error seems to be in phpcs. Can you paste your configuration file for me please

TNAJanssen commented 11 years ago

Here is my configuration:

{ // Plugin settings

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

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

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

// Show the error list after save.
"phpcs_show_errors_on_save": false,

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

// 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": [],

// 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": "/Applications/MAMP/bin/php/php5.4.4/bin/phpcs",

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

// PHP-CS-Fixer settings

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

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

// Path to where you have the php-cs-fixer installed
"php_cs_fixer_executable_path": "/usr/local/bin/php-cs-fixer",

// 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": "/Applications/MAMP/bin/php/php5.4.4/bin/phpcs",

// 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": ""
}

}

benmatselby commented 11 years ago

OK, this is rather strange.. I cannot replicate this, which is a concern.. Could you close ST2 down and re-open it (I know, very lame of me to ask)

TNAJanssen commented 11 years ago

Already did:P after each change in the config. hmm just tested a file which hasn't spaces in the directory! i will reinstall php-cs-fixer and come back with the results!

TNAJanssen commented 11 years ago

Didn't work! it looks like the command doesn't run!

TNAJanssen commented 11 years ago

Is there a way to get the output of the command so i can check what goes wrong?

benmatselby commented 11 years ago

Output? Unsure what you mean.. If you open up the console "View" > "Show Console", and make sure the "show_debug" setting is true, which it seems to be, that gives you all the debug information

TNAJanssen commented 11 years ago

I mean the output of php-cs-fixer, because only thing i see in console is: [Phpcs] /usr/local/bin/php-cs-fixer fix /Users/AJanssen/Dropbox/Easy Cloud/Projecten/Zend Modules/ACL/src/Service/Permission.php --verbose --level=all [Phpcs]

i can't see what php-cs-fixer gives back. I already reinstalled php-cs-fixer, phpcs and sublime-phpcs! I really don't want to reinstall sublime text:(

benmatselby commented 11 years ago

With that output, to me, that suggests that php-cs-fixer has not found anything to fix anymore. I get the same for files that have either a) been fixed or b) has nothing to fix inside it

TNAJanssen commented 11 years ago

That is weird! when i run it from terminal it says: MacBook-Pro-van-Alexander-Janssen:Site AJanssen$ php-cs-fixer fix /Users/AJanssen/Dropbox/Easy\ Cloud/Projecten/Zend\ Modules/ACL/src/Service/Permission.php --verbose --level=all 1) /Users/AJanssen/Dropbox/Easy Cloud/Projecten/Zend Modules/ACL/src/Service/Permission.php (controls_spaces)

benmatselby commented 11 years ago

Do you then do a revert on that file before trying in ST2? Either by git/svn/hg etc?

TNAJanssen commented 11 years ago

Yes i do a revert(dropbox), i also tried ST2 first then terminal!

benmatselby commented 11 years ago

I'll need to do further investigation on this when I'm not at work I'm afraid. Initial checks have left me unable to replicate this bug, which is worrying.

TNAJanssen commented 11 years ago

I'm will reinstall my sublime text 2 saturday, i hope that helps. If you want me to run commands or other things just ask.

jhoffmann commented 11 years ago

This is what I'm currently seeing in my ST console log:

[Phpcs] /usr/local/bin/php-cs-fixer fix /Users/jhoffmann/sugar/internal/custom/si_logic_hooks/LeadHooks.php --verbose --fixers=indentation,linefeed,trailing_spaces,unused_use,php_closing_tag,short_tag,return,braces,phpdoc_params,eof_ending,extra_empty_lines,controls_spaces,elseif
Traceback (most recent call last):
  File "./sublime_plugin.py", line 362, in run_
  File "./phpcs.py", line 486, in run
  File "./phpcs.py", line 356, in fix_standards_errors
  File "./phpcs.py", line 84, in get_errors
  File "./phpcs.py", line 175, in execute
  File "./phpcs.py", line 178, in parse_report
  File "./phpcs.py", line 92, in shell_out
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/subprocess.py", line 623, in __init__
    errread, errwrite)
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/subprocess.py", line 1141, in _execute_child
    raise child_exception
OSError: [Errno 8] Exec format error

The command it's running works fine if I copy it into a Terminal.

This is on OS X 10.7, with the following user config:

{
    "show_debug": true,

    "phpcs_additional_args": {
        "--standard": "/Users/jhoffmann/sugar/internal/custom/iapps_configs/phpcs/ruleset.xml",
        "-n": ""
    },

    "php_cs_fixer_on_save": true,
    "php_cs_fixer_show_quick_panel": true,
    "php_cs_fixer_executable_path": "/usr/local/bin/php-cs-fixer",
    "php_cs_fixer_additional_args": {
        "--fixers": "indentation,linefeed,trailing_spaces,unused_use,php_closing_tag,short_tag,return,braces,phpdoc_params,eof_ending,extra_empty_lines,controls_spaces,elseif"
    }
}
jhoffmann commented 11 years ago

Ok, figured out my problem, not sure if it will help others. I used Homebrew to install php-cs-fixer and the file it puts in /usr/local/bin is actually a symlink to a symlink to a wrapper around the actual binary.

/usr/local/bin/php-cs-fixer -> 
   /usr/local/Cellar/php-cs-fixer/0.1.0/bin/php-cs-fixer ->
      /usr/local/Cellar/php-cs-fixer/0.1.0/libexec/php-cs-fixer.phar

Setting php_cs_fixer_executable_path to the .phar in the plugin settings fixes it, apparently Python's subprocess doesn't like symlinks of symlinks of wrappers.

benmatselby commented 11 years ago

Thanks for the update John. I was baffled by this issue to be honest. Closing it down, as it doesn't sound like something that can be fixed in the plugin.

benmatselby commented 11 years ago

Updated the README to document the above