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": ...

Get Learning Node.js for .NET Developers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.