当前位置: 首页 > Web前端 > HTML

Eslint保存自动格式

时间:2023-03-27 23:08:06 HTML

vscodeeditsettingsvscodeinstalleslint,prettierplugin在settings文件中替换如下代码-->Preferences-->Settings{"workbench.colorTheme":"DraculaSoft","security.workspace.trust.untrustedFiles":"打开","bracketPairColorizer.depreciation-notice":false,"[vue]":{"editor.defaultFormatter":"octref.vetur"},"[html]":{"editor.defaultFormatter":"vscode.html-language-features"},"diffEditor.ignoreTrimWhitespace":false,"editor.codeActionsOnSave":{"source.fixAll.eslint":true},"eslint.format.enable":true,//启用autoFix默认情况下,只需要输入一个字符串数组"eslint.validate":["javascript","vue","html"]}.eslintrc.js文件配置module.exports={root:true,parserOptions:{parser:'babel-eslint',sourceType:'module',},env:{browser:true,node:true,es6:true,},extends:['plugin:vue/recommended','eslint:recommended'],rules:{semi:['error','always'],//在'vue/max-attributes-per-line':[2,{singleline:10,multiline:{max:1,allowFirstLine:false,},},],'vue/singleline-html-element-content-newline':'off','vue/multiline-html-element-content-newline':'off','vue/name-property-casing':['error','PascalCase'],'vue/no-v-html':'off','vue/html-self-closing':'off'},//在此处添加您的自定义规则//它基于https://github.com/vuejs/eslint-config-vue};项目添加.prettierrc.js格式文件配置,固定格式规则到项目module.exports={trailingComma:'es5',tabWidth:2,semi:true,singleQuote:true,bracketSpacing:true,//花括号加空格endOfLine:'lf',//换行符printWidth:150,//线宽,大于换行符vueIndentScriptAndStyle:false,};