技術浮浪貢

在 editor 混用 Prettier 與 ESLint

前篇 Prettier + ESLint 提過了兩者的合作方式,這篇主要是筆記在各主流 editor 下……

VSCode

Sublime Text 3

Packages:

Change settings of JsPrettifier:

 1{  
 2  // To use `prettier-eslint`
 3  "prettier_cli_path": "<path_to_prettier-eslint>",  
 4  
 5  // Format on Save
 6  "auto_format_on_save": true,  
 7  "auto_format_on_save_excludes": [  
 8    "*node_modules/*",  
 9    "*.json"  
10  ]  
11}

Vim 跟 WebStorm 的 Prettier plugin 都無法直接改用 prettier-eslint,所以

  1. 要用較複雜的方式存檔時自動格式化
  2. plugin 提供的 UI 指令只能使用原本的 Prettier

Vim

Plug-ins:

Add settings to .vimrc:

 1""" Use ESLint as linter of JavaScript
 2let g:syntastic_javascript_checkers = ['eslint']
 3let g:syntastic_javascript_eslint_exec = 'eslint'
 4
 5"""
 6""" for "Format on Save"
 7"""
 8autocmd BufWritePre
 9    \ *.js,*.jsx,*.mjs,*.ts,*.tsx,*.json,*.vue
10    \ Prettier
11set autoread  " Reload if file is changed outside of Vim
12
13let g:syntastic_javascript_eslint_args = [‘--fix’]
14function! SyntasticCheckHook(errors)
15  checktime  " Check file changes
16endfunction

WebStorm

All necessary plugins are built-in:

Use File Watcher to Format on Save

#ESLint #Prettier

« 上一篇

下一篇 »

相關文章