0

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.

  • You could try `autocmd BufRead,BufNewFile *.jsx let b:syntastic_checkers = ['eslint']`. This may or may not work with `syntastic_check_on_open`, depending on the order your Vim chooses to run `autocmd`s (the order is not well-defined). If it still runs `jshint` on open you might add a similar `autocmd` for `*.js`, and leave `g:syntastic_javascript_checkers` unset. – lcd047 Jun 21 '17 at 06:07
  • Thanks for leading me to an answer, @lcd047! – bradleyhop Jun 21 '17 at 18:49

1 Answers1

-1

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.

  • An `autocmd` on `BufEnter` will definitely not work with `syntastic_check_on_open`. Feel free to ignore me though. – lcd047 Jun 21 '17 at 20:02
  • @lcd047, maybe I found a bug then? I still get the same behavior as described above: jshint on javascript files, and eslint on *.jsx files. I also have `g:syntastic_check_on_open = 1` in my vimrc. I have the two checkers installed globally via npm. As the main contributor to syntastic, I do appreciate your help. Forgive me if I seemed a bit pedagogic (that's my teacher training and my own inexperience/excitement showing). – bradleyhop Jun 23 '17 at 15:52
  • 1
    The bug is in your understanding of what is supposed to happen. `check_on_open` runs on `BufRead`, and `BufRead` is applied before `BufEnter`. `b:syntastic_checkers` will be unset the _first_ time you run `check_on_open` in active mode. – lcd047 Jun 24 '17 at 02:37