Desired Behaviour
Linting of .js files with Sublime Text 3.
Actual Behaviour
No linting is taking place.
For example the following shows no errors:
var x = ""
Steps To Reproduce
Environment
Tools > SublimeLinter > Lint Mode > "Background"
Tools > SublimeLinter > Mark Style > "Fill"
In Sublime Text (to install SublimeLinter and JSHint plugin)
At Command Line
Install node.js, npm and jshint with:
sudo apt-get install nodejs npm
sudo npm install -g jshint
Quit and restart Sublime Text.
Troubleshooting
At Command Line:
hash -r
which jshint
returns
/usr/local/bin/jshint
I also tried this solution (https://stackoverflow.com/a/21203179/1063287) involving manuualy changing the path in Preferences > Package Settings > SublimeLinter > "Settings - User"
and restarted Sublime Text but there was no change:
"paths": {
"linux": ["/usr/local/bin/jshint"],
"osx": [],
"windows": []
},
Documentation Reference
On how to install jshint plugin:
https://github.com/SublimeLinter/SublimeLinter-jshint
UPDATE
I just ran this in command line - the results may help to troubleshoot:
jshint --version
/usr/bin/env: node: No such file or directory
This also comes up in Sublime Text Console:
SublimeLinter: WARNING: no jshint version could be extracted from:
/usr/bin/env: node: No such file or directory
This seems to make JSHint work - but if anyone could confirm that this is the best approach that would be great:
https://github.com/joyent/node/issues/3911#issuecomment-8956154
I've found this is often a misnaming error, if you install from a package manager you bin may be called nodejs so you just need to symlink it like so "ln -s /usr/bin/nodejs /usr/bin/node"
Note: Using this solution, no adjustments need to be made to paths in Preferences > Package Settings > SublimeLinter > "Settings - User"
.
The solution that you (the OP) provided will work, but I'll give some explanation, show you how to validate the issue, provide some other options and maybe a bit of best practice (which is what you were seeking when you posted the answer.
The problem is that the jshint executable is looking to run using the "node" interpreter, and the system can't find an executable that matches the name "node" in your path. (I believe that "node" used to be the standard name previously, but now it's generally referred to using "nodejs" because there was concern about the "node" name being to generic and conflicting with other executables.)
Here's how you can see what is going on... At the terminal, do the following: - find the path to the jshint executable by executing "which jshint" (you should find it in "/usr/local/bin") - view the contents by issuing "cat /usr/local/bin". You'll see that the first line specifies the interpreter to use, which is "node" (not "nodejs").
Currently, when you install Node.js using the package manager, the Debian package called "nodejs" creates the executable "/usr/bin/nodejs". Therefore, any other executables that specify the "node" executable don't find one and won't work.
You have many options:
The quickest and easiest. Create a symbolic link (effectively a "shortcut") for "node" that points to "nodejs". You had a version of this in your answer. It is generally accepted that it is a better practice to put this link in a location in your PATH other than in /usr/bin, such as in /usr/local/bin. The directory is protected, so you need superuser privileges to create the link in the destination. So, the command to issue is:
sudo ln -s /usr/bin/nodejs /usr/local/bin/node"
Alternatively, if you are on a system that doesn't have Node.js yet (or you remove the current package), when you install it via the package manager use the "nodejs-legacy" package (instead of nodejs). This package actually creates a link automatically for you. If you already have Node.js installed, you should remove it first.
sudo apt-get remove nodejs
sudo apt-get install nodejs-legacy
Finally, you could install Node.js manually or build it. This is more complicated and I won't try to explain all of that here.
You can validate that jshint can run now by issuing the command "jshint --version", which should now look something like this:
$ jshint --version
jshint v2.5.10
Happy Linting!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With