Sublime Forum

How to install linter (jshint)?

#1

Hello. I am attempting to install my first linter–jshint–using these instructions. But how can I test that I’ve installed it properly and that I’m using it? As I understand, if I introduce some errors/warnings in my code (e.g. remove a line-ending semi-colon), a small icon should appear in my gutter. But I don’t see any.

–If I open Tools–>SublimeLinter–>“Toggle linter…” I see that jshint is ‘enbabled’ (screenshot).

–If I enable Debug Mode, I can see the output:

reloading plugin SublimeLinter-jshint.linter
SublimeLinter: jshint linter loaded 

full output here

–If I try to run ‘jshint’ from the SublimeText command line, it outputs an error:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
NameError: name 'jshint' is not defined

I thought it might be an issue with my PATH (as described here). But I don’t see any of the errors indicated on that page.

Any help would be appreciated. Thanks in advance.

0 Likes

#2

Seems like you’re running into this problem: https://github.com/SublimeLinter/SublimeLinter3/issues/664. I have not the slightest idea what causes it. What happens if, without restarting Sublime, you disable en re-enable the SublimeLinter package?

0 Likes

#3

Thanks for the reply. But just to back up–how exactly do we know I have an issue? I’m still a bit new to this. Should running jshint at the SublimeText command line do something? If so, then I gather that returning not defined is a clear sign that installation did not occur as expected?

edit: I’ve posted my issue to that same Github issue thread. Thanks for that.

0 Likes

#4

Nope, that shouldn’t do anything.

0 Likes

#5

OK. I’m not sure where I read that–I can’t find that source anymore.

So in light of that, how can I even be sure that I have an issue? Maybe jshint installed properly and is working as expected, and I just don’t know it? How can I test that?

0 Likes

#6

You can switch SublimeLinter to debug mode and you should see the errors the linter finds in de console.

0 Likes

#7

OK thanks for the help so far. I’m interested in resolving this, or at least doing as much troubleshooting as possible.

You can switch SublimeLinter to debug mode.

Just to be clear, I can already enter debug mode in SublimeText by the shortcut ctrl+` Are you saying that SublimeLinter has a separate debug mode I can enable? If so, how would I do that?

0 Likes

#8

That’s not a debug mode, that just displays the console. Plugins sometimes have a debug setting that will write additional output to that console.

http://www.sublimelinter.com/en/latest/troubleshooting.html?highlight=debug

0 Likes

#9

Ah right, my mistake–thanks for correcting that. It turns out that I had already enabled debug mode for SublimeLinter. The only SublimeLinter items written to the console are:

SublimeLinter: jshint linter loaded 
SublimeLinter: jsxhint linter loaded 
SublimeLinter: debug mode: on 
SublimeLinter: temp directory: c:\users\snarl\appdata\local\temp\SublimeLinter3-snarl
0 Likes

#10

And does anything show up if you edit a javascript file and make errors? Also check if your linter needs a configuration file and if that’s available.

0 Likes

#11

OK hold on now. I just tried opening a different JS file. This time there was additional SublimeLinter output in the console. I have attached that output to the bottom of this post. Perhaps I didn’t have the debugger enabled after all?

Specifically, there is now a line SublimeLinter: WARNING: jshint deactivated, cannot locate 'jshint' Is this telling me the issue may lie with my $PATH? If I need to add the path to my jshint executable, how can I find that? I guess SublimeText was responsible for saving that to my computer? If so, I’m not sure where it saved it.

And does anything show up if you edit a javascript file and make errors?

No. As a test, I tried deleting an end-of-line semicolon, but no icon appeared in the gutter.

Also check if your linter needs a configuration file and if that’s available.

How can I check that? From its install page, I don’t think jshint requires a config file.

reloading plugin SublimeLinter-jshint.linter
SublimeLinter: jshint linter loaded 
reloading plugin SublimeLinter-jsxhint.linter
SublimeLinter: jsxhint linter loaded 
reloading plugin SublimeLinter.commands
reloading plugin SublimeLinter.sublimelinter
reloading plugin User.toggle_comment_cag8f
plugins loaded
SublimeLinter: debug mode: on 
SublimeLinter: temp directory: c:\users\snarl\appdata\local\temp\SublimeLinter3-snarl 
SublimeLinter: computed PATH from system:
C:\ProgramData\Oracle\Java\javapath
C:\WINDOWS\system32
C:\WINDOWS
C:\WINDOWS\System32\Wbem
C:\WINDOWS\System32\WindowsPowerShell\v1.0\
C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static
C:\Program Files (x86)\Windows Live\Shared
C:\Program Files (x86)\AMD\ATI.ACE\Core-Static
C:\HashiCorp\Vagrant\bin
C:\node\packages\
C:\node\packages\node_modules
C:\temp-c\nba-go
C:\temp-c\
C:\Program Files\nodejs\
C:\Program Files (x86)\Yarn\bin
C:\Users\snarl\AppData\Local\Microsoft\WindowsApps
C:\Users\snarl\AppData\Local\GitHubDesktop\bin
C:\Users\snarl\AppData\Roaming\npm
C:\Users\snarl\AppData\Local\Yarn\bin
 
SublimeLinter: WARNING: jshint deactivated, cannot locate 'jshint' 
Traceback (most recent call last):
  File "C:\Users\snarl\AppData\Roaming\Sublime Text 3\Packages\SublimeLinter\lint\util.py", line 247, in generate_color_scheme_async
    scheme_text = sublime.load_resource(scheme)
  File "C:\Program Files\Sublime Text 3\sublime.py", line 192, in load_resource
    raise IOError("resource not found")
OSError: resource not found
Package Control: No updated packages
0 Likes

#12

Well the debug output certainly helps. Is jshint in your path? What happens if you open CMD.exe and run jshint?

0 Likes

#13

Well the debug output certainly helps. Is jshint in your path?

I’m not sure. How can I find out the directory where jshint was saved? Am I correct that SublimeText was responsible for saving it to my computer? If so, shouldn’t I be able to look up the default save directory, or perhaps a log file? Or I guess I could uninstall the package, then re-install it and try to be mindful of output messages?

What happens if you open CMD.exe and run jshint?

It returns:

'jshint' is not recognized as an internal or external command,
operable program or batch file.
0 Likes

#14

Download and install NodeJS for Windows, latest stable version. Reboot. After this, open CMD.exe and type

npm install -g jshint

Then reboot again just for the sake of it. After this, try opening a .JS file in Sublime Text again and see if it’s working (it should).

It looks like you’ll need to install Python as well, by the looks of that .PY file that can’t be located in your logs.

0 Likes

#15

Thanks very much for the reply. I’d really like to get this working if I can. Here are my follow-ups:

Download and install NodeJS for Windows, latest stable version. Reboot. After this, open CMD.exe and type
npm install -g jshint

Done. The output of this was

C:\Users\snarl\.npm-global\jshint -> C:\Users\snarl\.npm-global\node_modules\jshint\bin\jshint
+ jshint@2.9.5
updated 1 package in 1.815s

Can you shed light on what this output means, especially the first line? I see there is a jshint file in each of the directories listed on the first line. But do I need to ensure one or both of those directories is in my PATH?

Then reboot again just for the sake of it. After this, try opening a .JS file in Sublime Text again and see if it’s working (it should).

I tried, but jshint does not appear to be working. The test I ran was to open a .JS file in SublimeText, then delete a line-ending semi-colon. No icon appeared in the gutter as I expected from jshint.

It looks like you’ll need to install Python as well, by the looks of that .PY file that can’t be located in your logs.

OK thanks for that.

One additional error message is:

SublimeLinter: WARNING: jshint deactivated, cannot locate 'jshint'

Do you think indicates a separate, possibly PATH related issue?

edit: As a test, I opened CMD and typed ‘jshint --version.’ It returned ‘file not found,’ which leads me to believe it is a PATH issue. Then, to my PATH I added C:\Users\snarl.npm-global. I ran ‘jshint --version’ again, and it returned the same thing (‘file not found’). I then rebooted my computer and ran it again. This time it returned jshint v2.9.5. I then opened a JS file in SublimeText and the output in the console was more promising. It found jshint and printed several errors in the JS file in-question. Also, in the SublimeText gutter now appeared jshint icons, as expected. There are still the missing py errors though. The SublimeText console output is:

SublimeLinter: jshint version query: C:\Users\snarl\.npm-global\jshint.cmd --version 
SublimeLinter: jshint version: 2.9.5 
SublimeLinter: jshint: (>= 2.5.0) satisfied by 2.9.5 
SublimeLinter: jshint activated: C:\Users\snarl\.npm-global\jshint.cmd 
Traceback (most recent call last):
  File "C:\Users\snarl\AppData\Roaming\Sublime Text 3\Packages\SublimeLinter\lint\util.py", line 247, in generate_color_scheme_async
    scheme_text = sublime.load_resource(scheme)
  File "C:\Program Files\Sublime Text 3\sublime.py", line 192, in load_resource
    raise IOError("resource not found")
OSError: resource not found
SublimeLinter: jshint: main-development.js ['C:\\Users\\snarl\\.npm-global\\jshint.cmd', '--verbose', '--filename', '@', '-'] 
SublimeLinter: jshint output:
C:\temp-c\codecanyon-8534570-cube-portfolio-responsive-wordpress-grid-plugin\cubeportfolio-wp-plugin\cubeportfolio\public\js\main-development.js: line 2, col 17, Missing semicolon. (W033)
C:\temp-c\codecanyon-8534570-cube-portfolio-responsive-wordpress-grid-plugin\cubeportfolio-wp-plugin\cubeportfolio\public\js\main-development.js: line 2685, col 43, This character may get silently deleted by one or more browsers. (W100)
C:\temp-c\codecanyon-8534570-cube-portfolio-responsive-wordpress-grid-plugin\cubeportfolio-wp-plugin\cubeportfolio\public\js\main-development.js: line 3592, col 6, Unnecessary semicolon. (W032)
C:\temp-c\codecanyon-8534570-cube-portfolio-responsive-wordpress-grid-plugin\cubeportfolio-wp-plugin\cubeportfolio\public\js\main-development.js: line 3901, col 6, Missing semicolon. (W033)
C:\temp-c\codecanyon-8534570-cube-portfolio-responsive-wordpress-grid-plugin\cubeportfolio-wp-plugin\cubeportfolio\public\js\main-development.js: line 4188, col 25, 'links' is already defined. (W004)
C:\temp-c\codecanyon-8534570-cube-portfolio-responsive-wordpress-grid-plugin\cubeportfolio-wp-plugin\cubeportfolio\public\js\main-development.js: line 4189, col 25, 'url' is already defined. (W004)
C:\temp-c\codecanyon-8534570-cube-portfolio-responsive-wordpress-grid-plugin\cubeportfolio-wp-plugin\cubeportfolio\public\js\main-development.js: line 4907, col 21, 'currentEl' is already defined. (W004)
C:\temp-c\codecanyon-8534570-cube-portfolio-responsive-wordpress-grid-plugin\cubeportfolio-wp-plugin\cubeportfolio\public\js\main-development.js: line 4908, col 21, 'top' is already defined. (W004)
C:\temp-c\codecanyon-8534570-cube-portfolio-responsive-wordpress-grid-plugin\cubeportfolio-wp-plugin\cubeportfolio\public\js\main-development.js: line 4909, col 21, 'end' is already defined. (W004)
C:\temp-c\codecanyon-8534570-cube-portfolio-responsive-wordpress-grid-plugin\cubeportfolio-wp-plugin\cubeportfolio\public\js\main-development.js: line 5203, col 41, Missing semicolon. (W033)
C:\temp-c\codecanyon-8534570-cube-portfolio-responsive-wordpress-grid-plugin\cubeportfolio-wp-plugin\cubeportfolio\public\js\main-development.js: line 6583, col 6, Missing semicolon. (W033)
C:\temp-c\codecanyon-8534570-cube-portfolio-responsive-wordpress-grid-plugin\cubeportfolio-wp-plugin\cubeportfolio\public\js\main-development.js: line 6767, col 13, 'forceWidthBlock' is already defined. (W004)

12 errors 
Package Control: Skipping automatic upgrade, last run at 2017-11-20 11:59:17, next run at 2017-11-20 12:59:17 or after

I guess we can consider this resolved then? Perhaps I will look into the ‘py’ errors separately.

0 Likes

#16

Hi,

It means jshint was installed “globally” in your system, and it can be accessed from anywhere on it;

Here’s a quick step-by-step on how I installed jshint on my Sublime Text 3 setup:

  1. Install latest version of ST3 (stable);

  2. Install latest version of NodeJS (stable);

  3. Install jshint, -g(lobally), via npm;

  4. Open ST3, install SublimeLinter via Package Control;

  5. Install SublimeLinter-jshint via Package Control;

  6. In ST3, go to Preferences, Package Settings, SublimeLinter, Settings;

  7. Add SublimeLinter-jshint path to the User Settings (window on the right) - you can copy the full contents of the default settings to the User Settings, then add to it:

     "paths": {
         "linux": [],
         "osx": [],
         "windows": [
             "/Users/snarl/.npm-global/node_modules/jshint/bin/jshint" // note how the slashes were replaced
         ]
     }
    
  8. Also, make sure jshint is enabled:

     "linters": {
         "jshint": {
             "@disable": false, // enable or disable linter
             "args": [],
             "excludes": []
         }
     }
    
  9. Restart ST3;

At this point, it should work. You won’t need Python installed, unless if you use a Python coded linter. In my case JSHint works without Python installed.

0 Likes

#17

OK thanks for that. The steps I carried out were identical to your steps 1-5 (and 8). But instead of steps 6 and 7, I added the jshint path to Windows via the steps described here. So far jshint seems to work without issue.

You won’t need Python installed, unless if you use a Python coded linter. In my case JSHint works without Python installed.

Well I’m still seeing the two console errors about missing ‘py’ files. But those might be related to specific jshint components–perhaps little used components.

Let’s consider this resolved while I continue to use/test it.

Thanks!

0 Likes