在您的主目录中创建(或编辑)名为 的文件.vimrc
,您可以通过将此行添加到您的.vimrc
let g:syntastic_javascript_checkers = ['jscs']
至于在写入时自动修复代码,请参阅此问题的答案:如何将 jscs 自动修复功能集成到 vim 中?
建议/更新
JSCS 现在与 ESlint 合并,所以你最终应该切换 linter,你可以编辑你的行.vimrc
以使用 'eslint' 代替;您可以使用文件或eslint 的配置文档.eslintrc
中详述的其他几个选项来配置 eslint,以使其了解 es6/react 的东西,目前我的设置可以在不同的情况下使用不同的 linter,如下所示:.vimrc
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
我已经修改了该答案中的代码以使用 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
应该在写入时或使用命令时自动修复代码:FixJS