So far, we have learned about complexity and code-coverage tools, but there are some other static-analysis tools we can use to lint our code based on different rules:
ESLint (https://www.npmjs.org/package/eslint)
JSHint (https://www.npmjs.org/package/jshint)
JSLint (https://www.npmjs.org/package/jslint)
JSLint is highly opinionated when it comes to the rules, while JSHint is more flexible. ESLint is the newest of the three and has support for pluggable rules.
Note
To find out more about the differences between JSHint and ESLint, read the blog post at http://www.nczonline.net/blog/2013/07/16/introducing-eslint/.
For our example, we will use ESLint using the following command:
$ npm i eslint ––save-dev
Before we run the eslint
command-line tool, we should create two files inside our root: .eslintignore
and eslint.json
. The first one indicates what files should be ignored:
node_modules/* test/* coverage/*
The second one is used for overriding the default configuration of eslint
:
{ ...