Use a Linter

November 6, 2015

I have been using a linter for over 2 months, I can’t believe how I could live without using one.

It’s not just about prettiness (which is what I thought before…) but it also makes your code safe and reliable.

By using a linter with your editor you can catch syntax errors even before running your code and it will detect code that could become problematic (unused variables, typos, constant checks, === over ==, left out debugger, etc…):

It also help you to learn about the language, by looking at the list of rules you can see what is possible and what is considered a best practice.

I had those moments where I asked myself:

  • Do like a space here or not?
  • Should it be { foo: 1 } or {foo: 1}?

Having rules written down and making the linter tell you what is correct, removes this cognitive process, which saves a huge amount of time.

I am using it for projects where I work alone but the biggest interested is when people are using it together: the convention is shared, anyone new to the project know what are the coding rules.

I got interesting conversations with my coworker about coding style they like :).

You can make the linter part of your continuous integration to ensure everyone is respecting the rules (yeah blame!).

So in conclusion:

Installation

I am using Atom as editor now. For javascript I’m using linter-eslint.

You can install globally ESLint by running:

npm install -g eslint

ESLint also provides an option to fix simple issues:

eslint --fix somefile.js

Comments

comments powered by Disqus