In your home directory create (or edit) the file named .vimrc
, You can tell syntastic which linter to use by add this line to your .vimrc
let g:syntastic_javascript_checkers = ['jscs']
As for automatically fixing your code on write, see the answers to this question: How can I integrate jscs autofix feature into vim?
Suggestion/Update
JSCS is now merged with ESlint, so you should eventually switch linters, you can edit the line in your .vimrc
to use 'eslint' instead; you can configure eslint with an .eslintrc
file, or several other options detailed in eslint's configuration docs to get it to understand the es6/react stuff, currently I've got my .vimrc
setup to use different linters in different situations like this:
if has("autocmd")
" use google/jshint for js "
autocmd FileType javascript.js let g:syntastic_javascript_checkers = ['gjslint','jshint']
" use eslint for jsx "
autocmd FileType javascript.jsx let g:syntastic_javascript_checkers = ['eslint']
else
" if an older version of vim without autocmd just use google/jshint "
let g:syntastic_javascript_checkers = ['gjslint','jshint']
endif
I've modified the code in that answer to work with eslint
function! FixJS()
"Save current cursor position"
let l:winview = winsaveview()
"run eslint fix on current buffer"
! eslint --fix %
"Restore cursor position"
call winrestview(l:winview)
endfunction
command! FixJS :call FixJS()
"Run the FixJS command just before the buffer is written for *.js files"
autocmd BufWritePre *.js FixJS
that should auto-fix code on write, or when using the command :FixJS