AUTOMATING
JAVASCRIPT STYLE CONVENTIONS

WHY?

JavaScript is like a former juvenile delinquent.

It's growing up and starting to get it's act together.

But it still needs a parole officer.

It's possible to write terrible JS that is still valid.

A clean, consistent code base is better to work on.

You can spend hours arguing over conventions.

Or you can settle on a set of conventions that everyone can live with and let automated tools enforce it.

JSHint

  • Static code analysis to detect potential errors and enforce JavaScript best practices.
     
  • Sensible set of defaults to avoid common gotchas.
     
  • Customizable to be as strict or as lax as you want it to be.

JSCS

  • Focuses on code style with over 90 validation rules that can be customized.
     
  • Has popular style guide presets like jQuery, Airbnb, Google, etc.
     
  • Plugins exist to use configuration for IDE auto-formatting

TOOLS

DEMO

OTHER TOOLS

EditorConfig

Config with plugins for editor settings
http://editorconfig.org/

Instanbul

Unit test code coverage reports
https://github.com/gotwarlost/istanbul

Plato

Source code static analysis and complexity
https://github.com/es-analysis/plato

NOW WHAT?

  • Install JSHint and JSCS plugins for your editor
     
  • Set up a CI server and have tasks run on every push to the repo
     
  • Set up a git pre-commit hook to run tasks before every commit (see: precommit-hook)

QUESTIONS?

http://smathson.github.io
smathson@gmail.com
@smathson

automating javascript style conventions

By Scott Mathson

automating javascript style conventions

  • 1,086