Skip to content

Instantly share code, notes, and snippets.

@sophieelsa
Last active December 21, 2020 18:06
Show Gist options
  • Save sophieelsa/53c9985111a44e05fe3c1906014864e8 to your computer and use it in GitHub Desktop.
Save sophieelsa/53c9985111a44e05fe3c1906014864e8 to your computer and use it in GitHub Desktop.

ESlint

ESLint is a tool which make code more consistent to follow common code style.

Concept

ESLint uses Espree for JavaScript parsing. ESLint uses an AST (Abstract Syntax Tree) to evaluate patterns in code. ESLint is completely pluggable, every single rule is a plugin and you can add more at runtime.

Installation and usage

We need Node.js >=12.0.0

  • You can install ESLint with npm or yarn undefined

or https://gist.github.com/496bf6659aaf0099b301838e2b544942

  • run eslint --init and you'll have .eslintrc.{js,yml,json} file in directory, where some rules configured as :

https://gist.github.com/438db996a22914e93712cdce068dd314

"space-in-parens"", "indent" ... are the names of rules in ESLint. The first value is the error level of the rule and can be one of these values:

  • "off" or 0 - turn the rule off
  • "warn" or 1 - turn the rule on as a warning (doesn't affect exit code)
  • "error" or 2 - turn the rule on as an error (exit code will be 1) You can see more configuration details on configuration docs We can use existing rules by extends, and this rules will be applied on.

https://gist.github.com/441cd8934cc0f71de82e1dd6bc80f51a

  • run ./node_modules/.bin/eslint --fix 'file.ts' to fix

Configuration example

https://gist.github.com/8f822dee5e10168c00682fcf385e9264

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