JSHint: A Static Code Analysis Tool for JavaScript
https://jshint.com/about/| Installer Source| Releases (json) (tab)
JSHint: A Static Code Analysis Tool for JavaScript
https://jshint.com/about/| Installer Source| Releases (json) (tab)
To update or switch versions, run npm install -g jshint@latest
(or @v2
,
etc).
These are the files / directories that are created and/or modified with this install:
~/.config/envman/PATH.env
~/.local/opt/node
~/.jshintrc.defaults.json5
~/.jshintrc.webi.json5
JSHint is a community-driven tool that detects errors and potential problems in JavaScript code. The project aims to help JavaScript developers write complex programs without worrying about typos and language gotchas. - jshint.com/about/
jshint
works best when it's integrated with your editor - such as vim
(with
vim-ale) or VS Code. However, you can also use it
from the CLI.
Here we'll cover how to:
Check out the official docs at https://jshint.com/docs/cli/ for more info.
JSHint is meant to be configure per-project.
You should put a .jshintrc
in the root of the repository of each of your
projects.
You can copy our recommended settings into your project directory by running this command:
# convert from JSON5 (with comments) to JSON and copy into current directory
sed -e 's://.*::g' \
~/.jshintrc.webi.json5 \
> .jshintrc
The .jshintrc
will be read by code tools such as vim-ale
and
VS Code
The primary value of tools like JSHint is that they allow you to restrict what you use in the language from "everything that could every be useful" down to just "safe features that don't cause bugs".
Given that, JSHint is perhaps a little too "flexible" - whereas its primary competitor (JSLint) is perhaps a little too inflexible - but if you follow that general methodology, you'll do well.
These are the settings we think strike the right balance for Software Engineering (as opposed to just Code Monkey-ing around):
// ~/.jshintrc.webi.json5
// Recommended config from https://webinstall.dev/jshint
//
// To copy this file into your project without comments, run this:
// sed -e 's://.*::g' ~/.jshintrc.webi.json5 > .jshintrc
{
browser: true,
node: true,
esversion: 11,
curly: true,
sub: true,
// More strict
bitwise: true,
eqeqeq: true,
forin: true,
freeze: true,
immed: true,
latedef: 'nofunc',
nonbsp: true,
nonew: true,
plusplus: true,
undef: true,
unused: 'vars',
strict: true,
maxdepth: 4,
maxstatements: 100,
maxcomplexity: 20,
}
That file is installed to ~/.jshintrc.webi.json5
, and should look pretty
similar to the above, assuming that we've kept it in sync with this README.
The list of JSHint's default options can be found here: https://github.com/jshint/jshint/blob/master/examples/.jshintrc
Give jshint
a list of files and/or directories to check .js
files:
jshint ./
Create a .jshintignore
to tell JSHint which files to ignore every time
echo "dist/" >> .jshintignore
You can use the overrides
directive to specify different rules to apply to
certain file patterns and directories.
{
esversion: 11,
overrides: {
'./browser/*.js': {
esversion: 7,
},
},
}