书写规范是非常重要的,除了统一,还要简洁。
在项目根目录新建.editorconfig
文件,加入设置:
# editorconfig.org
root = true
[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
在项目根目录新建.eslintrc.json
文件,加入设置:
{
"env": {
"browser": true,
"es2021": true,
"jquery": true // $不报错
},
"extends": [
"standard"
],
"parserOptions": {
"ecmaVersion": 12,
"sourceType": "module"
},
"rules": {
"space-before-function-paren": ["error", {
"anonymous": "always",
"named": "never",
"asyncArrow": "always"
}]
}
}
在VS Code的是settings.json插入:
{
"prettier.useEditorConfig": true,
"prettier.jsxSingleQuote": true,
"prettier.singleQuote": true,
"prettier.trailingComma": "none",
"prettier.semi": false,
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"editor.formatOnSave": false,
"editor.codeActionsOnSave": {
// For ESLint
"source.fixAll.eslint": true,
// For TSLint
"source.fixAll.tslint": true,
// For Stylelint
"source.fixAll.stylelint": true
},
"[html]": {
"editor.defaultFormatter": "HookyQR.beautify"
},
"files.exclude": {
"node_modules": true
},
}
希望对大家有用
联系客服