Skip to content

Instantly share code, notes, and snippets.

@avermeulen
Last active June 7, 2019 08:54
Show Gist options
  • Save avermeulen/5b67813781fc9980000bf395a8a8c4d4 to your computer and use it in GitHub Desktop.
Save avermeulen/5b67813781fc9980000bf395a8a8c4d4 to your computer and use it in GitHub Desktop.

ESLint intro

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.

Create a npm project

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 that npm init creates to your .gitignore file

Installing it

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

Configuring ESLint

{
    "extends": "standard",
    "rules" : {
        "indent": ["error", 4],
        "semi": [2, "always"]
    },
    "globals": {
        "describe" : true,
        "it" : true,
        "require" : true
    }
}

Add-ons

To make ESLint work in editors install these add-ons

VS Code install the ESLint extension

On Atom install: linter & linter-eslint packages

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment