benmatselby / sublime-phpcs

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

Can't fix OSError: [Errno 2] No such file or directory #116

Closed item4 closed 10 years ago

item4 commented 10 years ago

(I'm sorry. I can't english well..)

OS : OS X Sublime ver : 2 PHP : PHP 5.4.24 PHP_CodeSniffer : newest. installed globally by composer PATH : /Library/Frameworks/Python.framework/Versions/3.4/bin:/Users/item4/.composer/vendor/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin

My sublime occur OSError: [Errno 2] No such file or directory and can't fix it.

to test, I added one line

print cmd, info, home, sys.version

and it's error traceback on console

['phpcs', '--report=checkstyle', '-n', '--standard=PSR2', '/Users/item4/Downloads/test.php'] None /Users/item4 2.6.8 (unknown, Mar  9 2014, 22:16:00) 
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)]
Traceback (most recent call last):
  File "./sublime_plugin.py", line 362, in run_
  File "./phpcs.py", line 600, in run
  File "./phpcs.py", line 425, in run
  File "./phpcs.py", line 139, in get_errors
  File "./phpcs.py", line 215, in execute
  File "./phpcs.py", line 218, in parse_report
  File "./phpcs.py", line 169, 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 2] No such file or directory

So, I tried directly on python26

Python 2.6.8 (unknown, Mar  9 2014, 22:16:00) 
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess
>>> cmd = ['phpcs', '--report=checkstyle', '-n', '--standard=PSR2', '/Users/item4/Downloads/test.php']
>>> proc = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
>>> proc.stdout
<open file '<fdopen>', mode 'rb' at 0x1043cf1e0>
>>> proc = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, startupinfo=None, cwd='/Users/item4')
>>> proc.communicate()[0]
'<?xml version="1.0" encoding="UTF-8"?>\n<checkstyle version="1.5.3">\n<file name="/Users/item4/Downloads/test.php">\n <error line="2" column="10" severity="error" message="Expected 1 newline at end of file; 0 found" source="PSR2.Files.EndFileNewline.NoneFound"/>\n</file>\n</checkstyle>\n'
>>> import sys
>>> sys.version
'2.6.8 (unknown, Mar  9 2014, 22:16:00) \n[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)]'
>>> 

and I tried phpcs.

item4-macbook-proui-MacBook-Pro:~ item4$ phpcs --report=checkstyle -n --standard=PSR2 /Users/item4/Downloads/test.php
<?xml version="1.0" encoding="UTF-8"?>
<checkstyle version="1.5.3">
<file name="/Users/item4/Downloads/test.php">
 <error line="2" column="10" severity="error" message="Expected 1 newline at end of file; 0 found" source="PSR2.Files.EndFileNewline.NoneFound"/>
</file>
</checkstyle>

I can't understand this error. I hope fix it.

benmatselby commented 10 years ago

Sounds like you need to define:

"phpcs_executable_path": "/Users/Ben/.composer/vendor/bin//phpcs",

Where the path is what you get when you do

$ which phpcs

Sublime Text does not use your $PATH, so you have to specify full paths in the config file.

item4 commented 10 years ago

I forgot attempt my config

{
    "font_face": "나눔고딕코딩",
    "font_size": 13,
    "ignored_packages":
    [
        "Vintage"
    ],
    "phpcs_executable_path": "/Users/item4/.composer/vendor/bin/phpcs"
}

I added config value. but I can't run yet.

benmatselby commented 10 years ago

I think you may need to put this in the plugin user config, which you can get to via Preferences > Package Settings > PHP Code Sniffer > User Settings.

If you turn on debug as well, that will show you in the console everything it is doing. You should see the full path to phpcs being used.

item4 commented 10 years ago

oh, now it run. thx to advice.

i wish to add description about how to config it because I did not know how to config plugins. :(

benmatselby commented 10 years ago

It is in the readme on the front page of this repo: https://github.com/benmatselby/sublime-phpcs#configuration

And there are also example configurations https://github.com/benmatselby/sublime-phpcs/tree/master/example-settings