ESLint

What we'll cover
- Discuss purpose of linters, specifically ESLint
- Wiring up ESLint to a project with webpack
- ESLint syntax
- ESLint and your text editor
Purpose of linting

What is linting?
The term was derived from the name of the undesirable bits of fiber and fluff found in sheep's wool.
Finds syntactic and/or stylistic discrepancies and potential programming errors
Purpose of linting
Benefits of linting your code
- Save time
- Maintain quality
- Consistent code in a group

VS



Purpose of linting
Other Linters
JsLint
JsHint

¯\_(ツ)_/¯
Purpose of linting
Benefits of ESLint
- Unopinionated
- Allows devs to create custom rules to suit style
- Has 3 preset themes
- Has a react plugin
USing eslint
Stuff to Install
$ npm install -g eslint$ npm install babel-eslint eslint-loader eslint-plugin-reactUSing eslint
Writing an eslintrc.js
$ eslint --initHow would you like to configure ESLint?
> Answer questions about your style
Use a popular style guide
Inspect your JavaScript file(s)USing eslint
Common JS Styles
Which style guide do you want to follow?
> Google
Airbnb
StandardUSing eslint
Wiring to Webpack
module: {
preLoaders: [{
test: /^(?!.*spec.jsx$).*\.jsx$/i,
loaders: ['eslint'],
exclude: ['/node_modules/',
'./webpack.config.js',
'/__tests__/'
]
}],eslint: {
failOnWarning: false,
failOnError: true
},ESLINT Syntax
Rule Name
"no-unused-vars": [1, {"vars": "local", "args": "after-used"}],Strength of Rule
Options
2: error
1: warn
0: don't track
Allows for further customization of a rule
"prefer-const": 2,"semi": [1, "always"],"no-ternary": 0,ESLINT and your text editor
-
Atom
- linter-eslint
-
Sublime Text
- SublimeLinter
- SublimeLinter-contrib-eslint
- Plus a little more config (article)
- VSCode
-
WebStorm
- ESLint
Helpful links
ESLint
By Valerie Kraucunas
ESLint
HG Front End Chapter Presentation 1/2017
- 822