[英]How to get Airbnb's JavaScript style eslint guide working in vim with react, es6?
I am fairly new to vim, and starting a new javascript project with editor as vim(currently learning as well). 我对vim相当陌生,并用vim作为编辑器开始了一个新的javascript项目(目前也在学习中)。
I found that there are some presets for style-guide, and linting provided by Airbnb , Google and some others. 我发现有一些由Airbnb , Google和其他提供的样式指南和棉绒的预设。 I also found that I can use syntastic vim plugin which can help me enable linting and style-check in vim.
我还发现我可以使用syntastic vim插件,该插件可以帮助我在vim中启用linting和样式检查。
But I can't figure out how to link these things in vim? 但是我不知道如何在vim中链接这些东西? What configuration files I need to create and how to enable these features in Syntastic vim plugin?
我需要创建哪些配置文件,以及如何在Syntastic vim插件中启用这些功能? Also I want to enable jscs autofix on file save feature.
我也想在文件保存功能上启用jscs自动修复。
Edit: I am also using react with es6. 编辑:我也使用与es6反应。
Any basic or details direction, tutorial link to achieve the same will be helpful. 任何基本或详细的指导,实现相同的教程链接都将有所帮助。
Thanks 谢谢
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
在你的主目录创建(或编辑)命名的文件
.vimrc
,你可以告诉使用由该行添加到您的syntastic其中棉短绒.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? 至于在写时自动修复代码,请参见以下问题的答案: 如何将jscs自动修复功能集成到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; JSCS现在与ESlint合并,因此您最终应该切换短绒,您可以在
.vimrc
编辑该行以使用'eslint'代替; 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: 您可以使用
.eslintrc
文件或eslint的配置文档中详细介绍的其他几个选项来配置eslint,以使其了解es6 / react东西,目前,我已经将.vimrc
设置为在不同情况下使用不同的linters:
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 我已经修改了该答案中的代码以与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
在写时或使用命令时应自动修复代码
:FixJS
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.