vscode-settings.json配置(prettier + eslint)
command + p 搜尋到settings.json檔案,檔案配置及註釋如下
"workbench.iconTheme": "vscode-icons-mac", "editor.renderIndentGuides": false, "cSpell.ignoreWords": ["antd"], //編輯器失去焦點時自動儲存更新後的檔案 "files.autoSave": "onFocusChange", "workbench.colorTheme": "Monokai", "git.confirmSync": false, "window.title": "${activeEditorLong}${separator}${rootName}", "window.zoomLevel": 0, "editor.fontSize": 14, //為了符合eslint的兩個空格間隔原則 "editor.tabSize": 2, // 檔案頭部註釋 "fileheader.Author": "niuchunling", "fileheader.LastModifiedBy": "niuchunling", //關閉編輯器預設程式碼檢查,為了不跟eslint配置衝突 "editor.formatOnSave": false, "javascript.format.enable": false, //eslint 格式化外掛,儲存時應用eslint規則自動格式化後儲存 "eslint.autoFixOnSave": true, "prettier.eslintIntegration": true, // 去掉程式碼結尾分號 "prettier.semi": false, "git.path": "/usr/bin/git", "editor.fontFamily": "Microsoft YaHei,Menlo, Monaco, 'Courier New', monospace", "editor.fontWeight": "bold", "javascript.updateImportsOnFileMove.enabled": "never", "explorer.confirmDragAndDrop": false } 複製程式碼
2、 設定專案自己的規則
在專案根目錄新建.vscode資料夾,資料夾中新建settings.json覆蓋全域性的setings.json檔案,配置同上
tips: 以上都是基於幾個前提
- 編輯器安裝了Prettier - Code formatter 外掛並啟用
- 專案配置了使用eslint
- fileheader相關配置是安裝了Document This外掛