Skip to content

Instantly share code, notes, and snippets.

@kernelwhisperer
Last active December 2, 2018 12:57
Show Gist options
  • Save kernelwhisperer/a8beb62c854ee3c8816a3a2ba20bfcda to your computer and use it in GitHub Desktop.
Save kernelwhisperer/a8beb62c854ee3c8816a3a2ba20bfcda to your computer and use it in GitHub Desktop.

Linting & formatting with ESLint

Programmer errors & best practices: standard

Style issues: prettier

Note: configs can export plugins as well!

ESLint

npm i -D eslint - Pluggable linting utility

Standard

npm i -D eslint-config-standard eslint-plugin-standard eslint-plugin-promise eslint-plugin-import eslint-plugin-node

{
  "extends": ["standard"]
}

Note standard also exports:

{
  "env": {
    "es6": true,
    "node": true
  }
}

Prettier

npm i -D prettier eslint-plugin-prettier eslint-config-prettier

  1. eslint-config-prettier - ESLint rules that are unnecessary or that will conflict prettier (e.g.: comma-dangle, space-before-function-paren)
  2. eslint-plugin-prettier - ESLint plugin that will run prettier when you run eslint
{
  "extends": ["plugin:prettier/recommended"]
}

Ava

npm i -D eslint-plugin-ava

{
  "extends": ["plugin:ava/recommended"]
}

Babel

npm i -D babel-eslint

{
  "parser": "babel-eslint"
}

Workflow

npm i -D husky lint-staged

Test linting:

npm run lint

{
  "lint": "eslint src test && documentation lint src test",
}

Lint on commit:

{
  "husky": {
    "hooks": {
      "pre-commit": "lint-staged"
    }
  },
  "lint-staged": {
    "linters": {
      "*.js": [
        "eslint --fix",
        "documentation lint",
        "git add"
      ]
    }
  }
}

VS Code

Install dbaeumer.vscode-eslint In settings.json:

{
  "eslint.autoFixOnSave": true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment