書(shū)寫(xiě)規范是非常重要的,除了統一,還要簡(jiǎn)潔。
在項目根目錄新建.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
},
}
希望對大家有用
聯(lián)系客服