Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make Syntastic load a different checker based on existance of files in root?

At work we use a different syntax checker than I do when working on open source. Is there a way to have Syntastic specify a default checker, and change checkers if an rc file is found at the project root?

Example: if .eslintrc is found use eslint. If no .eslintrc is found, use standard.

Thanks!

edit: also opened an issue on scrooloose/syntastic.

like image 641
Yoshua Wuyts Avatar asked Feb 17 '15 23:02

Yoshua Wuyts


2 Answers

Yes, you can do something like this:

autocmd FileType javascript let b:syntastic_checkers = findfile('.eslintrc', '.;') != '' ? ['eslint'] : ['standard']

Edit: Upon request, explanation of how this works:

  • autocmd FileType javascript - run the following stuff every time the filetype of a buffer is set to javascript (that is, normally once per buffer)
  • b:syntastic_checkers list of checkers enabled for the current buffer, overriding g:syntastic_javascript_checkers
  • findfile('.eslintrc', ...) - find a file named .eslintrc ...
  • .; - ... in the current directory and upwards
  • != '' ? - if found...
  • ['eslint'] - ... set b:syntastic_checkers to ['eslint']
  • : ['standard'] - ... otherwise set it to ['standard']

Magic, I tell ya.

like image 68
lcd047 Avatar answered Nov 15 '22 02:11

lcd047


Another simple option, which has wider application than just this question, is to add the following to your .vimrc file:

if findfile('.lvimrc','.') != ''
    source .lvimrc
endif

Then in the directory where you want some different behavior, just add a '.lvimrc' file with the syntastic option that you want for that directory.

like image 39
Mike Jarvis Avatar answered Nov 15 '22 00:11

Mike Jarvis