簡體   English   中英

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

[英]How to get Airbnb's JavaScript style eslint guide working in vim with react, es6?

我對vim相當陌生,並用vim作為編輯器開始了一個新的javascript項目(目前也在學習中)。

我發現有一些由AirbnbGoogle和其他提供的樣式指南和棉絨的預設。 我還發現我可以使用syntastic vim插件,該插件可以幫助我在vim中啟用linting和樣式檢查。

但是我不知道如何在vim中鏈接這些東西? 我需要創建哪些配置文件,以及如何在Syntastic vim插件中啟用這些功能? 我也想在文件保存功能上啟用jscs自動修復。

編輯:我也使用與es6反應。

任何基本或詳細的指導,實現相同的教程鏈接都將有所幫助。

謝謝

在你的主目錄創建(或編輯)命名的文件.vimrc ,你可以告訴使用由該行添加到您的syntastic其中棉短絨.vimrc

let g:syntastic_javascript_checkers = ['jscs']

至於在寫時自動修復代碼,請參見以下問題的答案: 如何將jscs自動修復功能集成到vim中?


建議/更新

JSCS現在與ESlint合並,因此您最終應該切換短絨,您可以在.vimrc編輯該行以使用'eslint'代替; 您可以使用.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

我已經修改了該答案中的代碼以與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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM