Linting is the process of running a program that will analyze your code for potential errors. A lint program does this by using a set of rules applied to your code to determine if any violations have occurred.

When it comes to analyzing JavaScript program errors, ESLint is the best linting tool available today. Not only does it include a large set of rules for potential errors and style violations. It is also pluggable which enables anyone to write their own rules and custom configurations.

However, my favorite feature is the ability to auto-fix using the --fix flag. Integrating auto-fix provides constant feedback by cleaning up mistakes and keeping code clean before you check it in to a repository. If you are involved in an open source project, it also saves time by ensuring that the code you contribute doesn’t require clean up or other work from other contributors.

I like to do this cleanup by saving a file in my editor as it provides a quick feedback loop and persists the fixed changes to disk. In this article, I am going to show you how to do that for a few popular editors. Here is the endgame:


Installing ESLint

You an install ESLint locally for a given project or globally for all projects on a system. We will focus on using a global ESLint for this tutorial, but note that many of these plugins support a local install as well.

First, install ESLint globally:

npm install -g eslint


For Vim users, just add the fixmyjs package using your preferred packaging tool like vim-plug or Vundle:

" Plug
Plug ruanyl/vim-fixmyjs
" Vundle
Plugin ruanyl/vim-fixmyjs

Then, to format on save, just add the following to your .vimrc:

au BufWritePre *.js :Fixmyjs
au BufWritePre *.jsx :Fixmyjs

Sublime Text

For Sublime, using Package Control, install the ESLint-Formatter package. Then, to format on save, add the following to the Preferences -> Package Settings -> ESLint-Formatter -> Settings  —  User file:

  "format_on_save": true


For Atom, install the linter-eslint package. Then, configure it like this:


Note that this assumes your global Node installation is at /usr/local which is typical, but not always the case. Run npm get prefix and paste that value into this field if ESLint cannot be found.

Other editors

If your editor is not represented above, there may be a plugin or a way to use the eslint command directly to achieve a similar effect.

For example, the vim plugin will run the following:

eslint -c <path-to-config> --fix <path-to-current-file>

Then, reload the file in the buffer.

Happy auto-formatting!