vsCode中配置EsLint,使代碼保存後根據項目中.eslint配置文件自動格式化代碼;
安裝下載所需vs code插件
- HTML Snippets(html代碼補全)
- ESLint(代碼風格檢查與規範)
- vetur (語法高亮)
- Prettier - Code formatter (只關注格式化,並不具有eslint檢查語法等能力,只關心格式化文件(最大長度、混合標籤和空格、引用樣式等),包括JavaScript · Flow · TypeScript · CSS · SCSS · Less · JSX · Vue · GraphQL · JSON · Markdown)
修改vsCode配置
- 打開vsCode:文件-首選項-設置,選擇在setting.json文件中修改配置
setting.json配置代碼
{
// 重新設定tabsize
"editor.tabSize": 2,
// 文件關聯
"files.associations": {
"*.vue": "vue",
"*.js": "javascript",
"*.ejs": "html"
},
// #每次保存的時候自動格式化
"eslint.autoFixOnSave": true,
// eslint配置項
"eslint.options": {
"configFile": "./.eslintrc.js",
"extensions": [
"html",
".js",
".vue"
]
},
"eslint.validate": [
"javascript",
// 添加 vue 支持
{
"language": "vue",
"autoFix": true
},
// 添加 html 支持
{
"language": "html",
"autoFix": true
}
],
// 檢索過濾
"search.exclude": {
"**/node_modules": true,
"**/bower_components": true,
"**/dist": true
},
"emmet.syntaxProfiles": {
"javascript": "jsx",
"vue": "html",
"vue-html": "html"
},
"extensions.ignoreRecommendations": false,
"explorer.confirmDelete": false,
"git.confirmSync": false,
"window.zoomLevel": 0,
"editor.renderWhitespace": "boundary",
"editor.cursorBlinking": "smooth",
"editor.minimap.enabled": true,
"editor.minimap.renderCharacters": false,
"editor.codeLens": true,
"editor.snippetSuggestions": "top",
"[vue]": {
"editor.defaultFormatter": "octref.vetur"
},
}