-
Notifications
You must be signed in to change notification settings - Fork 12
Using JSHint with Geany
A tutorial how to install and use JSHint with JavaScript file within Geany:
We are going to run JSHint via Node.js. Everything is available to install through Ubuntu apt-get.
- Install Node.js & npm (Node Package Manager):
$ sudo apt-get install nodejs npm
- Install jshint (via npm):
$ sudo npm install jshint -g
On Windows, JSHint can run with built-in Windows Script Host so there are less things to prepare:
- Download JSHint source from Github
- Extract the files to a folder with short and easy access path. For example "C:\jshint". There should be "jshint.js" file and "env" folder inside.
- Download my WSH runner patch for Geany: wsh-geany.js and copy to the "env" folder in "C:\jshint".
FYI, I have patched the wsh.js file in JSHint so that it generates output compatible with Geany's Error Regular Expression. You'll have the convenience of Geany jumping to the error line when click on the compile error output.
Setup up custom build command in Geany for JavaScript file:
- Make sure no project is opened (so that the settings will be applied globally)
- Open any JavaScript file (*.js)
- Go to menu Build > Set Build Commands
- At JavaScript Commands, click on the first "Set menu item label" button, type in "JSHint"
- For the command, type in:
- Ubuntu/Linux:
jshint %f
- Windows:
cscript C:\jshint\env\wsh-geany.js %f
(assuming you place JSHint in suggested path above)
- Ubuntu/Linux:
- For the working directory, type in
%d
- To enable error highlight in source file, copy this pattern into "Error Regular Expression": (Same for Ubuntu & Windows)
(.+):\ line\ ([0-9]+)
- OK to apply and close the setting window
From now you can run JSHint on opening JavaScript file by clicking the Compile button on menu bar OR go to Build > JSHint OR press F8. The output will displayed at Compiler panel at the bottom.
NOTE: On some Ubuntu based systems JSHint will fail to execute, the output would be something like /usr/bin/env: node: No such file or directory
. This is because the package manager installs the binary as /usr/bin/nodejs
instead of /usr/bin/node
, to fix this just run the following command in the terminal:
$ ln -s /usr/bin/nodejs /usr/bin/node