How to enable JSHint in SublimeLinter in Linux Mint 17 Cinnamon?
Asked Answered
B

2

5

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

  • Linux Mint 17 Cinnamon
  • Sublime Text Build 3065
  • Tools > SublimeLinter > Lint Mode > "Background"
  • Tools > SublimeLinter > Mark Style > "Fill"

In Sublime Text (to install SublimeLinter and JSHint plugin)

  • ctrl+shift+p
  • Package Control: Install Package
  • Install SublimeLinter
  • Install SublimeLinter 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://mcmap.net/q/1056710/-sublime-text-3-sublimelinter-plugin-not-able-to-find-jshint) 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
Bonny answered 21/11, 2014 at 15:54 Comment(0)
B
5

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".

Bonny answered 22/11, 2014 at 6:52 Comment(1)
As you stated, that will work, but per your request, I've provided an answer below to tell you why/how and some alternatives.Bookish
B
5

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

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").

The Cause

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.

The Fix

You have many options:

  1. 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"
  2. 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.

    • To remove "nodejs" package:
      sudo apt-get remove nodejs
    • Install "nodejs-legacy" (the one with the link)
      sudo apt-get install nodejs-legacy
  3. 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.

Validation

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!

Bookish answered 30/11, 2014 at 5:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.