JavaScript Linting

Michael Trotter

Jane.com

"lint"?!

​C's `lint` tool

jslint

jshint

              jscs (js code style)

eslint

                standardjs (eslint presets)

safety

  1. ​unused variables
  2. == vs ===
  3. throw "string" (see: reasons)
  4. switch statements mistakes
  5. shadowing/hiding outer variables
  6. restricting module use​​ (underscore + lodash)

style

  1. infamous semicolons
  2. indentation (tabs vs spaces, 2 vs 4)
  3. alignment
  4. 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

  1. safety
    • ​don't repeat mistakes!
    • steer devs in the right direction
  2. standardization
    • ​consistency
    • easier to jump around in large code bases

cons

  1. less flexible
  2. quick & dirty is cool too
  3. more configuration
  4. error overload!
  5. 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
  }
}
Made with Slides.com