vscode格式化配置
-
准备 安装插件eslint、prettier - Code formatter、vetur -
配置setting.json {
"files.autoSave": "onFocusChange",
"vetur.format.defaultFormatter.html": "prettyhtml",
"vetur.format.defaultFormatter.css": "prettier",
"vetur.format.defaultFormatter.postcss": "prettier",
"vetur.format.defaultFormatter.scss": "prettier",
"vetur.format.defaultFormatter.less": "prettier",
"vetur.format.defaultFormatter.stylus": "stylus-supremacy",
"vetur.format.defaultFormatter.js": "prettier",
"vetur.format.defaultFormatter.ts": "prettier",
"vetur.format.defaultFormatter.sass": "sass-formatter",
"eslint.validate": ["javascript", "javascriptreact", "vue"],
"vetur.format.defaultFormatterOptions": {
"prettier": {
"trailingComma": "es5",
"tabWidth": 2,
"useTabs": false,
"semi": false,
"singleQuote": true,
"arrowParens": "avoid"
}
},
"editor.formatOnSave": false,
"editor.formatOnType": false,
"editor.formatOnPaste": false,
"editor.wordWrap": "off",
"editor.detectIndentation": false,
"editor.tabSize": 2,
"editor.insertSpaces": false,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"[vue]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[jsonc]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
}
-
.eslinttrc.js – 项目配置校验规则 module.exports = {
root: true,
env: {
browser: true,
es6: true,
node: true
},
'extends': [
'eslint:recommended',
'plugin:vue/recommended',
'@vue/standard'
],
rules: {
'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
'quotes': ['error', 'single'],
'semi': ['error', 'never'],
'no-extra-semi': 'error',
'vue/html-end-tags': 'error',
'vue/require-default-prop': 'off',
'vue/require-prop-types': 'error',
'vue/attributes-order': 'error',
'vue/order-in-components': 'error',
'vue/html-indent': ['error', 2],
'vue/attribute-hyphenation': ['error', 'always'],
'vue/html-quotes': ['error', 'double'],
'vue/arrow-spacing': ['error', { 'before': true, 'after': true }],
'vue/block-spacing': ['error', 'always'],
'vue/component-name-in-template-casing': ['error', 'kebab-case', {
'registeredComponentsOnly': true,
'ignores': []
}],
'vue/eqeqeq': ['error', 'always'],
'handle-callback-err': ['error', '^(err|error)$']
},
parserOptions: {
parser: 'babel-eslint'
}
}
-
.prettierrc.js – 项目格式化配置 module.exports = {
semi: false,
singleQuote: true,
trailingComma: 'none',
bracketSpacing: true,
proseWrap: 'preserve'
}
|