73rhodes / Sublime-JSLint

JSLint for Sublime Text 2 and 3.
80 stars 14 forks source link

Troubleshooting [Errno 2] No such file or directory #25

Closed alexpyoung closed 10 years ago

alexpyoung commented 10 years ago

My build system was working yesterday before you merged https://github.com/darrenderidder/Sublime-JSLint/pull/21. I updated the User Settings file as instructed and am now receiving the following error:

[Errno 2] No such file or directory
[cmd:  [u'node', u'/Users/Alex/Library/Application Support/Sublime Text 2/Packages/JSLint/linter.js', u'--predef', u"['angular', 'document', '\\$', '_', 'JQuery', 'FB']", u'--sloppy', u'--indent', u'2', u'--node', u'--nomen', u'--vars', u'--plusplus', u'--stupid', u'--todo', u'/Applications/MAMP/htdocs/Project/assets/js/service.js']]
[dir:  /Applications/MAMP/htdocs/Project/assets/js]
[path: /usr/bin:/bin:/usr/sbin:/sbin]
[Finished]

I can still run node from the command line with the 'node'. Any ideas of what's wrong?

darrenderidder commented 10 years ago

What's your operating system and version.

alexpyoung commented 10 years ago

Mac OS X 10.9.2

darrenderidder commented 10 years ago

Does it run when you empty the JSLint User Settings? What version of JSLint does Package Control indicate you have?

alexpyoung commented 10 years ago

Nope, same error.

darrenderidder commented 10 years ago

Tools - Command Pallete - Package Control : List Packages; which version of JSLint?

alexpyoung commented 10 years ago

Couldn't find a version number, but it looks like it was dated 8/26/2013

darrenderidder commented 10 years ago

Run Tools-Command Palette - Package Control: Upgrade Packages

alexpyoung commented 10 years ago

All my packages are currently upgraded

darrenderidder commented 10 years ago

You should have JSLint v.2014.04.03.04.04.35 (under Tools - Command Palette - Package Control: List Packages)...?

alexpyoung commented 10 years ago

Oops. Yes, that is the version I have.

darrenderidder commented 10 years ago

MacOS worked for me so will need to dig deeper. Can you send your settings if they've been modified... will try to reproduce it.

alexpyoung commented 10 years ago

Sublime User Settings?

{
    "color_scheme": "Packages/Color Scheme - Default/Solarized (Light).tmTheme",
    "detect_indentation": true,
    "font_size": 14,
    "ignored_packages":
    [
    ],
    "tab_size": 4,
    "translate_tabs_to_spaces": true,
    "use_tab_stops": true
}
alexpyoung commented 10 years ago

I appreciate you taking time to look into it. Do you accept PayPal donations?

darrenderidder commented 10 years ago

No, Preference - Package Settings - JSLint - Settings - Default and User

alexpyoung commented 10 years ago

Default:

{
    // an array of options to pass to jslint.
    "options" : [

        // examples using predef flag.
        "--predef", "['angular', 'document', '\\$', '_', 'JQuery', 'FB']"
        // tolerate missing 'use strict' pragma.
        ,"--sloppy"
        // suggest an indent level of two spaces.
        ,"--indent", "2"
        // assume node.js to predefine node globals.
        ,"--node"
        // tolerate unfiltered for in.
        //,"--forin"
        // tolerate dangling _ in identifiers.
        ,"--nomen"
        // tolerate many var statements per function.
        ,"--vars"
        // tolerate ++ and --.
        ,"--plusplus"
        // tolerate Douglas Crockford.
        ,"--stupid"
        ,"--todo"

    ]

    // if true, run jslint on save.
    ,"run_on_save" : true

    // a regex string to determine whether jslint
    // should be run on a file.
    // if a match is found (i.e. re.search(filename_filter, filename)),
    // the file will be linted.
    ,"filename_filter": "(\\.js|\\.json|\\.html|\\.sass|\\.less|\\.html)$"

    // jslint command you want to run as an array of strings.
    // E.g.: ["jslint"] or ["/usr/local/bin/jslint"] or ["node", "mylinter.js"]
    // Default is
    //    * Linux: ["node", "~/.config/sublime-text-2/Packages/JSLint/linter.js"]
    //    * Mac: ["node", "~/Library/Application Support/Sublime Text 2/Packages/JSLint/linter.js"]
    //    * Windows: ["node", "%APPDATA%/Sublime Text 2/Packages/JSLint/linter.js"]

    // ,"jslint" : ["jslint"]

    // if your own personal choice of jslint has an output
    // different from the standard which comes with this package,
    // you may have to change line_regex and file_regex
    // check http://docs.sublimetext.info/en/latest/reference/build_systems.html
    // to find out how these regular expressions work. The defaults are:

    // ,"line_regex" : ".*// Line ([0-9]*), Pos ([0-9]*)$"
    // ,"file_regex" : "(^[^# ]+.*$)"
}

User settings are empty

darrenderidder commented 10 years ago

Both these files exist on your system? /Users/Alex/Library/Application Support/Sublime Text 2/Packages/JSLint/linter.js /Applications/MAMP/htdocs/Project/assets/js/service.js

alexpyoung commented 10 years ago

Yes, the error is not unique to any specific JavaScript file. Any file I try to run JSLint on produces the same error (different file name of course)

darrenderidder commented 10 years ago

From the command line: which node

alexpyoung commented 10 years ago

/usr/local/bin/node

darrenderidder commented 10 years ago

Try copying the default settings to user settings and modify user settings ,"jslint": ["/usr/local/bin/node", "~/Library/Application Support/Sublime Text 2/Packages/JSLint/linter.js"]

alexpyoung commented 10 years ago

After running it with the modified user settings:

module.js:340
    throw err;
          ^
Error: Cannot find module '/Applications/MAMP/htdocs/Project/assets/js/~/Library/Application Support/Sublime Text 2/Packages/JSLint/linter.js'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:902:3
[Finished in 0.1s with exit code 8]
darrenderidder commented 10 years ago

Can you paste the modified user settings?

alexpyoung commented 10 years ago
{
    // an array of options to pass to jslint.
    "options" : [

        // examples using predef flag.
        "--predef", "['angular', 'document', '\\$', '_', 'JQuery', 'FB']"
        // tolerate missing 'use strict' pragma.
        ,"--sloppy"
        // suggest an indent level of two spaces.
        ,"--indent", "2"
        // assume node.js to predefine node globals.
        ,"--node"
        // tolerate unfiltered for in.
        //,"--forin"
        // tolerate dangling _ in identifiers.
        ,"--nomen"
        // tolerate many var statements per function.
        ,"--vars"
        // tolerate ++ and --.
        ,"--plusplus"
        // tolerate Douglas Crockford.
        ,"--stupid"
        ,"--todo"

    ]

    // if true, run jslint on save.
    ,"run_on_save" : true

    // a regex string to determine whether jslint
    // should be run on a file.
    // if a match is found (i.e. re.search(filename_filter, filename)),
    // the file will be linted.
    ,"filename_filter": "(\\.js|\\.json|\\.html|\\.sass|\\.less|\\.html)$"

    // jslint command you want to run as an array of strings.
    // E.g.: ["jslint"] or ["/usr/local/bin/jslint"] or ["node", "mylinter.js"]
    // Default is
    //    * Linux: ["node", "~/.config/sublime-text-2/Packages/JSLint/linter.js"]
    //    * Mac: ["node", "~/Library/Application Support/Sublime Text 2/Packages/JSLint/linter.js"]
    //    * Windows: ["node", "%APPDATA%/Sublime Text 2/Packages/JSLint/linter.js"]

    ,"jslint": ["/usr/local/bin/node", "~/Library/Application Support/Sublime Text 2/Packages/JSLint/linter.js"]

    // if your own personal choice of jslint has an output
    // different from the standard which comes with this package,
    // you may have to change line_regex and file_regex
    // check http://docs.sublimetext.info/en/latest/reference/build_systems.html
    // to find out how these regular expressions work. The defaults are:

    // ,"line_regex" : ".*// Line ([0-9]*), Pos ([0-9]*)$"
    // ,"file_regex" : "(^[^# ]+.*$)"
}
darrenderidder commented 10 years ago

For the jslint property can you try replacing "~/" with "/Users/Alex/" ?

alexpyoung commented 10 years ago

That fixed the issue! Would you mind quickly explaining your debugging thought process and why this solution solved the problem?

darrenderidder commented 10 years ago

Just reading the error messages and process of elimination mainly. That last error is node complaining about not finding a module; the message seems to indicate a weird shell expansion taking place and substituting the tilde for your current working directory. I don't know if this is an issue for all recent Macs and not sure of long-term solution yet.

darrenderidder commented 10 years ago

http://stackoverflow.com/questions/22700025/zsh-tilde-expands-differently-on-os-x

alexpyoung commented 10 years ago

Hmm, do you think that tilde substitution might also have to do with modifications to my .bashrc or .bash_profile? I might have modified it at some point without fully understanding what I was doing

darrenderidder commented 10 years ago

Possibly. echo ~; echo $HOME; file ~/.bashrc could be informative.

alexpyoung commented 10 years ago

echo ~; echo $HOME; file ~/.bashrc; file ~/.bash_profile:

/Users/Alex
/Users/Alex
/Users/Alex/.bashrc: ASCII English text
/Users/Alex/.bash_profile: ASCII text
darrenderidder commented 10 years ago

references https://bugzilla.mozilla.org/attachment.cgi?id=8394338&action=diff https://docs.python.org/2/library/os.path.html

darrenderidder commented 10 years ago

Could you beta test this: Replace the JSLint.py script with

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sublime
import sublime_plugin
import re
import os

EXEC_LINT = 'js_lint_exec'
SETTINGS_FILE = 'JSLint.sublime-settings'

class JsLintExecCommand(sublime_plugin.WindowCommand):

    def run(self, files=[]):
        settings = sublime.load_settings(SETTINGS_FILE)
        self.window.run_command('exec', {
            'cmd':
                map(os.path.expanduser, settings.get('jslint', ['node', sublime.packages_path() + '/JSLint/linter.js']))  +
                settings.get('options', []) +
                files,
            'line_regex': settings.get('line_regex', '.*// Line ([0-9]*), Pos ([0-9]*)$'),
            'file_regex': settings.get('file_regex', '(^[^# ]+.*$)')
        })

class JsLintOnSave(sublime_plugin.EventListener):

    def on_post_save(self, view):
        settings = sublime.load_settings(SETTINGS_FILE)
        if settings.get('run_on_save', False) == False:
            return
        if re.search(settings.get('filename_filter'), view.file_name()):
            view.window().run_command(EXEC_LINT, {
                'files': [view.file_name()]
            })

# Support calls to the old API of the JSLint package.

class JslintCommand(sublime_plugin.WindowCommand):

    def run(self):
        self.window.run_command(EXEC_LINT, {
            'files': [self.window.active_view().file_name()]
        })

and revert your user settings to the default.

darrenderidder commented 10 years ago

This may not solve the /usr/local/bin path issue but should fix the tilde expansion.

alexpyoung commented 10 years ago

It seems to be working with the modifications to the Python file and default User Settings

darrenderidder commented 10 years ago

From node Mac OS X package installer:

The installation was completed successfully Node was installed at /usr/local/bin/node npm was installed at /usr/local/bin/npm Make sure that /usr/local/bin is in your $PATH.

To do this in your ~/.bashrc file add this line: export PATH=/usr/local/bin:$PATH

You may want to add current directory's node_modules folder also, then the line would be: export PATH=/usr/local/bin:./node_modules/.bin:$PATH

alexpyoung commented 10 years ago

Will do. Thank you for your time

darrenderidder commented 10 years ago

Updated package should be available shortly via Tools - Command Palette - Package Control : Upgrade Packages. Please upgrade and confirm the fix. Feel free to close if the issue is resolved. Cheers... thanks for helping to troubleshoot this.