Search code examples
vimjshinteslintsyntastic

Change Vim's Syntastic to use a certain checker based on file extension?


I have vim's syntastic installed properly along with eslint and jshint. I prefer jshint for most of my javascript programming. However, I'm starting to learn React, and would like to use eslint with syntastic (eslint has superior/proper linting for react).

Is it possible to set vim to use jshint for *.js files, and eslint for *.jsx files?

I see from :help syntastic-checkers that react gets lumped in javascript. Chaining the linters is not what I want, either.


Solution

  • Found it! You were very close @lcd047, but your comment lead me down the right path! To enable eslint on only *jsx files, putting the following in my .vimrc works:

    au BufEnter *.jsx let b:syntastic_checkers = ['eslint']

    In my case, syntastic will use jshint on javascript by default even if a checker is not set in .vimrc. Setting the above works even if g:syntastic_javascript_checkers is unset or even if it is set, in my case, to jshint.