好的环境配置不仅可以提高效率减少错误的产生,更能够约束所有的参与人员。
使用prettier进行代码格式化
.prettierrc.json
{
"printWidth": 80,
"semi": true,
"singleQuote": true,
"trailingComma": "all",
"arrowParens": "always",
"tabWidth": 2,
"useTabs": false
}
这里简单的使用几个配置项来对代码进行快速的格式化操作 vscode需要安装Prettier+插件
使用editorconfig约束编辑器
.editorconfig
root = true
[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
max_line_length = 80
trim_trailing_whitespace = true
[*.md]
max_line_length = 0
trim_trailing_whitespace = false
使用typescript
npm i -D typescript
npx typescript --init
然后配置tsconfig.json即可
使用EsLint检查代码错误
npm i -D eslint
npx eslint --init
# 然后根据需要配置Eslint