We all like Vim. It has been around for a long time and it has helped us to increase our productivity. Linting is another essential tool we rely on our everyday life. It makes our code easier to understand and follow. That applies to new people joining our projects later on and also our future selves.
Considering that you have eslint set up, it’s really easy to add linting support to the Vim.
If syntax errors are detected, the user is notified and is happy because they didn’t have to compile their code or execute their script to find them.
The following steps will guide in how to install Syntastic along with eslint support.
The assumption here is that eslint and required NPM packages are already installed in your project.
Installation process is straightforward. If you use Vundle as plug-in manager, add the following line in your
.vimrc; and then run
Otherwise if you use pathogen as the plug-in manager, check out project’s github as there are installation steps provided there.
After Syntastic is installed we need to tweak our
vimrc. The default options are not well-suited for new users. I suggest that you add the lines below to your
set statusline+=%*let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 1
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0
This will add eslint syntax checker to your vim. This enables vim to use
npm run lint command to run eslint against our files when needed.
Normally I add a lint script directive to my
package.json as global eslint doesn’t run the eslint version installed in a project.
"lint": "eslint .",
You are all set. Running
:SyntasticInfo should return some information about version and enabled checkers.
If something goes wrong and you don’t see any linting feedback on your screen it’s time to debug.
- examine the output, this will put you in a starting point to debug further
Voila. Happy viming.