沒法格式化有不少種狀況,多種因素形成,多是setting.json 也多是eslintrc.js 形成。javascript
"eslint.validate": [
"javascript",
"javascriptreact",
{
"language": "html",
"autoFix": true
},
{
"language": "vue",
"autoFix": true
}
],
複製代碼
<script>
tags{
"workbench.iconTheme": "vscode-icons",
"window.zoomLevel": 0,
"editor.renderWhitespace": "all",
"editor.insertSpaces": true,
"editor.tabSize": 4,
"editor.trimAutoWhitespace": false,
"explorer.confirmDragAndDrop": false,
"editor.detectIndentation": false,
"eslint.validate": [
"javascript",
"javascriptreact",
{
"language": "html",
"autoFix": true
},
{
"language": "vue",
"autoFix": true
}
],
"eslint.options": {
"plugins": ["html","vue"]
},
"workbench.editor.enablePreviewFromQuickOpen": false,
"explorer.confirmDelete": false,
"editor.wordWrap": "on",
"workbench.sideBar.location": "left",
"extensions.ignoreRecommendations": true,
"debug.inlineValues": true,
"window.menuBarVisibility": "visible",
"workbench.editor.enablePreview": false,
"breadcrumbs.enabled": true,
"workbench.statusBar.feedback.visible": false,
"javascript.format.insertSpaceBeforeFunctionParenthesis": true,
"javascript.updateImportsOnFileMove.enabled": "always",
"files.eol": "\r\n",
"editor.wordSeparators": "`~!@#$%^&*()=+[{]}\\|;:'\",.<>/?",
"vetur.format.defaultFormatter.html": "none",
"vetur.format.defaultFormatter.js": "none",
"eslint.autoFixOnSave": true,
"eslint.alwaysShowStatus": true,
"eslint.enable": true,
"files.autoSave": "off",
}
複製代碼
autoFixOnSave 看是否需求自動格式化html
// http://eslint.org/docs/user-guide/configuring
module.exports = {
root: true,
// parser: "babel-eslint",
"parserOptions": {
"parser": "babel-eslint",
"ecmaVersion": 2017,
"sourceType": "module"
},
env: {
browser: true,
},
// https://github.com/feross/standard/blob/master/RULES.md#javascript-standard-style
extends: ["standard", "eslint:recommended", "plugin:vue/essential"],
// required to lint *.vue files
plugins: [
"vue"
],
// add your custom rules here
"rules": {
//"off"或 0 -關閉規則
//"warn" 或 1 - 開啓規則, 使用警告 程序不會退出
//"error"或 2 - 開啓規則, 使用錯誤 程序退出
"indent": [2, 4],
//分號
"eqeqeq": 0,
"no-useless-escape": 0,
"brace-style": 0,//大括號風格
"curly": [2, "all"], //[2, "all"],//必須使用 if(){} 中的{}
"no-new": 0,
"no-return-assign": "warn",//return 語句中不能有賦值表達式
"handle-callback-err": 0,
"padded-blocks": 0,
"no-duplicate-imports": 0,
"operator-linebreak": 0,
"no-extend-native": 0,
"no-sequences": 0,
"no-debugger": 0,
"no-eval": 0,
"comma-dangle": [2, "never"],
"arrow-spacing": [2, { "before": true, "after": true }],
"no-undef": 2,
"no-console": 0,
"space-before-function-paren": [2, "always"],
"keyword-spacing": [2, { "before": true, "after": true }],
"space-before-blocks": [2, "always"],
"spaced-comment": [2, "always", {"exceptions": ['-', '+']}],
"quotes": [2, "double"],
"semi": [2, "never"],
"no-multiple-empty-lines": [2, {"max": 1}],
"generator-star-spacing": [2, { "before": true, "after": true }],
"object-curly-newline": ["error", { "consistent": true, "minProperties": 2 }],
"object-curly-spacing": [2, "always"],
"key-spacing": [2, { "beforeColon": false, "afterColon": true }],
"linebreak-style": [2, "windows"],
"eol-last": [2, "windows"],
"object-property-newline": [2, {}],
"space-infix-ops": 2,
"vue/html-indent": [2, 4, {
"attribute": 1,
"baseIndent": 1,
"closeBracket": 0,
"alignAttributesVertically": true,
"ignores": []
}],
"no-control-regex": 0
},
globals: {
"_": true,
"arguments": true,
"ActiveXObject": true,
"AndroidLogin": true
}
}
複製代碼
下面這段代碼可解決template
沒法格式化狀況。 有些無用的可刪除,按現有公司的規範來vue
"vue/html-indent": [2, 4, {
"attribute": 1,
"baseIndent": 1,
"closeBracket": 0,
"alignAttributesVertically": true,
"ignores": []
}],
複製代碼