Eslint 配置教學

如圖,可以快速裝好airbnb規範

輸入這個指令

npx eslint --init

安裝完之後,在webStorm的設定那邊開啟eslint

之後就會看到一堆可怕的紅線惹。然後再搭配prettier
再新增.prettierrc檔案

{
  "printWidth": 100,
  "singleQuote": true
}

還有.prettierignore檔看情況配置

之後再存檔,就會發現雙引號變成單引號惹!
※有問題就重開IDE
※有時候存檔沒變化,是因為檔案沒變,可以空一行再存試試

介紹二個套件:
eslintconfigprettier
turns off all ESLint rules that could conflict with Prettier
eslintpluginprettier
integrates the Prettier rules into ESLint rules

EsLint規則查詢

EsLint和Prettier有衝突的話怎麼辦?
官方網頁有推薦的套件
看這篇就解決了:
How to make ESLint work with Prettier avoiding conflicts and problems

參考:
Getting Started with ESLint – ESLint – Pluggable JavaScript linter
Prettier · Opinionated Code Formatter
Set up ESlint, Prettier & EditorConfig without conflicts