A quick intro to ESLint
Whether you’re a part of a team or working on a project by yourself, ESLint is a great way to ensure clean, consistent code and identify bugs before they ever make their way into production.
The ESLint Gem
Jon Kessler and Justin Force created a handy ESLint gem for Rails. You simplify create a configuration file in
rake eslint:run, and it will check your
application.js file for any issues.
If you’re looking for a solid eslint config file, check out the one we at Automattic use for Calypso.
Customing the workflow
I wound up customizing how I use the the gem for two reasons:
- The gem checks
application.js, the line numbers that ESLint spits out in its report don’t correspond to the line numbers in the individual files, making it difficult to pinpoint the offending lines of code.
With this in place, you can run
$ rake lint:run
48:5 low indent Expected indentation of 3 tab chrs but found 4
49:5 low indent Expected indentation of 3 tab chrs but found 4
50:5 low indent Expected indentation of 3 tab chrs but found 4
612:3 slow quote-props Unnecessarily quoted property `class` found
613:28 low quote-props Unnecessarily quoted property `class` found
915:1 low valid-jsdoc Missing JSDoc parameter type for 'reason'
If you also use ESLint in your Rails project, I’d love to hear more about your setup.