Checking code style with ESLint
Although we don't need a compiler, we can still benefit from having the computer perform static analysis of our code. Linting tools are common in many languages for spotting common programming errors that may lead to subtle bugs or confusing code. You may be familiar with CodeRush, StyleCop, and others for .NET, or CheckStyle, Findbugs, Sonar, and others for Java.
We'll be using a JavaScript/ECMAScript linting tool called ESLint. Let's first install it globally:
> npm install -g eslint
Now create a config file to tell ESLint what rules to use as .eslintrc.json
:
{ "extends": "eslint:recommended", "env": { "node": true, "es6": true, "mocha": true, "browser": true, "jquery": true }, "rules": { "semi": [2, "always"], "quotes": [2, "single"] } }
Here, we tell ESLint to use its standard recommended rules for the environments that we are using in our scripts. We also tell it to check for semicolons...