ESLint

June 22, 2016

Linting is cool. It keeps people from making stupid mistakes and can make your code a lot neater/easier to read.

Not linting is how you end up with spaghetti code that no one can read.

Lint everything. HTML, CSS, JS, Python, Ruby, PHP, etc.

ESLint lints JS really nicely.

There was JSHint and JSLint, but they were hard to extend so someone made a JS linter that was easy to extend called ESLint. It’s now the standard.

Agree with your team on a coding style. This part isn’t super important and there are a ton of well thought out configs out there already like AirBnB. What’s important is you all agree to do the same code style!

How to use ESLint

Use npm. It’s easy and portable.

Note: I feel ya. All of these npm packages seem silly, but it’s the whole Unix philosophy of making everything modular. It’s a bit annoying, but overall it’s usually a good thing.

Protip: If you’re configuring some npm package, see if you can put it in package.json instead of having 20 config files polluting the root of your project.

What if I have some global variables? jQuery doesn’t work! alert() is throwing an error!

Config it!

"eslintConfig": {
  "extends": "airbnb",
  "env": {
    "jquery": true
  },
  "rules": {
    "no-alert": "off"
  }
}

Congrats

Now you’re linting your JS like a pro. Enjoy your impending OCD.

Homework