简体   繁体   English

如何使Airbnb的JavaScript样式eslint指南与React,ES6一起在vim中工作?

[英]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. 我发现有一些由AirbnbGoogle和其他提供的样式指南和棉绒的预设。 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.

相关问题 Airbnb的ES6风格指南功能推荐 - Airbnb's ES6 style guide recommendation about functions 如何使用 Airbnb JavaScript 风格指南设置 Prettier - How do I set up Prettier with Airbnb JavaScript Style Guide 如何运行Airbnb javascript样式指南中的代码? - How do I run the code in the Airbnb javascript style guide? 如何将 eslint airbnb 风格指南合并成一个文件以复制到 package.json 中? - How can I concatinate the eslint airbnb style guide into one file to copy into package.json? 带有 Airbnb 风格指南的 ESLint 不适用于所有规则 - ESLint with Airbnb style guide does not work for all rules Airbnb样式指南:命名约定的规则不起作用 - Airbnb style guide:rules for naming conventions not working 通过解构或forEach进行缩减-迭代和Airbnb JavaScript样式指南 - Reduce with deconstruction or forEach - Iteration and Airbnb JavaScript Style Guide 将 ESLint 与 Airbnb 样式和选项卡 (React.js) 结合使用 - Use ESLint with Airbnb style and tab (React.js) 为什么即使我将其设置为两个空格和硬制表符,Eslint 仍会在 atom 中使用 Airbnb 样式指南的两个空格规则引发错误? - why does Eslint throws error with the Airbnb style guide's two spaces rule in atom even though I have it set to two spaces and hard tabs? 如何在Javascript / ES6中获得这样的输出 - How to get output like this in Javascript/ES6
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM