ESLint checks if your JavaScript for errors and if it meets the configured coding standard.
You can read more about linting here or here. ESLint help us to find bugs in our JavaScript code quicker. It check for things like undefined variables or functions and prevent runtime errors in the process.
To install eslint
in your local project you need to be in a npm project. Make your current folder one by doing this
npm init --save
Note: Ensure to add the
node_modules/
folder thatnpm init
creates to your.gitignore
file
Do this in your project folder.
npm install --save-dev eslint
Configure it using:
node_modules/.bin/eslint --init
OR
npx eslint --init
Now select:
- CommonJS - for the module system
- None of these - for frameworks
- Node - for where your code run (use space bar to toggle)
- JSON - for What format do you want your config file to be in
{
"extends": "standard",
"rules" : {
"indent": ["error", 4],
"semi": [2, "always"]
},
"globals": {
"describe" : true,
"it" : true,
"require" : true
}
}
To make ESLint work in editors install these add-ons
VS Code install the ESLint
extension
On Atom install: linter
& linter-eslint
packages