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

Created on 18 Feb 2015  路  6Comments  路  Source: vim-syntastic/syntastic

_Originally posted on StackOverflow but also opening here for reference._

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!

Most helpful comment

Yes, you can do something like this:

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

All 6 comments

Yes, you can do something like this:

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

@lcd047 thanks a lot!

Does it still work?
I tried and I can't see any syntax error even if I force one. This is my :SyntasticInfo output:

Syntastic version: 3.8.0-3 (Vim 800, Darwin)
Info for filetype: javascript.jsx
Global mode: active
Filetype javascript.jsx is active
The current file will be checked automatically
Available checkers: javascript/eslint javascript/standard
Currently enabled checker: javascript/eslint

This is the .eslintrc I have in project's root directory:

{"extends": ["standard"], "parser": "babel-eslint"}

Another team member uses the WebStorm IDE and it requires a .eslintrc in order to have standard working, as described here: http://standardjs.com/webstorm.html

So, basically:

  • My Syntastic configuration is using eslint
  • The project's eslint configuration is using stantard

But I can't see any warning/error when I save or open a file with a ;, for example:
img1

If I change my configuration to use only stantard as my default checker I can see it working:
img2

Please open your test file, set g:syntastic_debug to 3, run the checker, run :mes, and post the output. Please use copy & paste rather than screenshots.

thanks @lcd047, debugging showed me that some packages was missing and that I should installed those globally :)

I implemented checker detection rules for most JavaScript and TypeScript checkers for my own use (e.g. looking for .eslintrc with various extensions, "eslintConfig" in package.json, etc.). I packaged it as a plugin (kevinoid/syntastic-detect-checkers) in case anyone else is interested in sharing checker detection rules. If there is any interest in including the rules in Syntastic, I would be happy to help merge it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dunatotatos picture dunatotatos  路  6Comments

duckpuppy picture duckpuppy  路  8Comments

HabbaRazzer picture HabbaRazzer  路  5Comments

mollerhoj picture mollerhoj  路  5Comments

olalonde picture olalonde  路  3Comments