JavaScript Linting
Michael Trotter
Jane.com
"lint"?!
C's `lint` tool
jslint
jshint
jscs (js code style)
eslint
standardjs (eslint presets)
safety
- unused variables
- == vs ===
- throw "string" (see: reasons)
- switch statements mistakes
- shadowing/hiding outer variables
- restricting module use (underscore + lodash)
style
- infamous semicolons
- indentation (tabs vs spaces, 2 vs 4)
- alignment
- where should the spaces go??
fixing files
jshint: github.com/jshint/fixmyjs
jscs: jscs src --fix
standardjs: standard --format
.editorconfig
[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
pros
- safety
- don't repeat mistakes!
- steer devs in the right direction
- standardization
- consistency
- easier to jump around in large code bases
cons
- less flexible
- quick & dirty is cool too
- more configuration
- error overload!
- false sense of security
- linters aren't type systems!
.eslintrc
---
extends:
- standard
.eslintrc
{
"extends": ["standard"]
}
.eslintrc
{
"parser": "babel",
"extends": ["eslint:recommended"]
}
.eslintrc
{
"parser": "babel",
"extends": ["eslint:recommended"],
"plugins": [
"plugin1"
],
"rules": {
"eqeqeq": 0,
"curly": 2,
"quotes": [2, "double"],
"plugin1/rule1": 2
}
}
javascript-linters
By spicydonuts
javascript-linters
- 908