VScode的配置格式化代码
tab缩进风格
- 输入tabsize - 设置tab缩进为2个空格
format格式化
- format
创建项目之eslint的规范
- 选择的是
ESLint + Standard config
标准的规范!
eslints常见的报错
6:1 error More than 1 blank line not allowed no-multiple-empty-lines
就是在第6行代码之中,出现多余的空格!
8:7 error Missing space before function parentheses space-before-function-paren
在第8行代码之中函数的参数前必须带空格!init() -> init ()
- 取消这个控制:
'space-before-function-paren': 0,
VScode之中
- 在应用商店里面下载安装eslint
- 配置eslint 在设置之中搜索
setting
- 同理安装:
Prettier - Code formatter
setting.json 配置
{
"editor.codeActionsOnSave": {
"source.fixAll": true
},
"eslint.alwaysShowStatus": true,
"prettier.configPath": "C:\\Users\\XXXX\\.prettierrc",
"prettier.trailingComma": "none",
"prettier.semi": false,
"prettier.printWidth": 300,
"prettier.singleQuote": true,
"prettier.arrowParens": "avoid",
"prettier.jsxBracketSameLine": false,
"prettier.jsxSingleQuote": false,
"vetur.format.defaultFormatter.html": "js-beautify-html",
"vetur.ignoreProjectWarning": false,
"vetur.format.defaultFormatterOptions": {
"js-beautify-html": {
"wrap_attributes": false
},
"prettyhtml": {
"printWidth": 300,
"singleQuote": false,
"wrapAttributes": false,
"sortAttributes": false
},
"prettier": {
"trailingComma": "none",
"semi": false,
"singleQuote": true,
"arrowParens": "avoid",
"printWidth": 300
}
},
}
在你c盘目录下拉进去此文件.prettierrc
{"semi": false, "singleQuote": true, "printWidth": 300}
.eslintrc.js
module.exports = {
root: true,
env: {
node: true
},
extends: [
'plugin:vue/vue3-essential',
'@vue/standard'
],
parserOptions: {
parser: 'babel-eslint'
},
rules: {
'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
'indext': 0,
"semi": [2, "always"],
'space-before-function-paren': 0,
'array-bracket-newline': 0,
'prefer-const1': "off",
"no-dupe-args": 2,
'quotes': "off",
"semi": "off",
"comma-dangle": "off",
'no-multi-spaces': ["error", {
ignoreEOLComments: false
}],
'arrow-parens': ['error', 'as-needed', {
requireForBlockBody: true,
}],
"arrow-parens": 0,
"arrow-spacing": 0,
"no-mixed-spaces-and-tabs": [0],
'no-irregular-whitespace': 'off',
'generator-star-spacing': 0
}
}