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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With