jscs, .jscsrc, vim, syntastic, and you
Published 2015-2-10If you're a real JavaScript developer, you've been using jshint
with
syntastic
and or
sublimelinter
and it's been working wonderfully for you.
But apparently the node core devs prefer jscs
,
which requires a slight config change to your .vimrc
.
I want to contribute to a project created by a node core guy, he wants me to use jscs.
Good Mythical Morning! Let's talk about that.
vim + jscs
First, follow the syntastic installation instructions to install both pathogen and syntastic.
Then install jscs from npm.
npm install -g jscs
Your .vimrc
should contain these three lines:
.vimrc:
# this line goes first because pathogen needs bash (not csh, zsh, fish, etc)
set shell=bash
call pathogen#infect()
syntax on
Finally, you have to choose how you want to use jscs
:
If you don't care to use jshint
.vimrc:
let g:syntastic_javascript_checkers=['jscs']
If you still want to use both
Let's say you have a ~/.jshintrc
, but in specific projects
you have a ./.jscsrc
, you'd want something like this after
your call pathogen#infect()
:
function! JavascriptLinter(curpath)
let parent=1
let local_path=a:curpath
let local_jscs=local_path . '.jscsrc'
while parent <= 255
let parent = parent + 1
if filereadable(local_jscs)
return ['jscs']
endif
let local_path = local_path . "../"
let local_jscs = local_path . '.jscsrc'
endwhile
unlet parent local_jscs
return ['jshint']
endfunction
let g:syntastic_javascript_checkers=JavascriptLinter(getcwd() . "/")
UPDATE:
I hear you can also do it this way:
autocmd FileType javascript let b:syntastic_checkers = findfile('.jscsrc', '.;') != '' ? ['jscs'] : ['jshint']
See https://github.com/scrooloose/syntastic/issues/974#issuecomment-73837549
By AJ ONeal
Did I make your day?
Buy me a coffee
(you can learn about the bigger picture I'm working towards on my patreon page )