项目搭建规范
一、代码规范
1.1集成editorconfig配置
EditorConfig 有助于为不同 IDE 编辑器上处理同一项目的多个开发人员维护一致的编码风格。
# http://editorconfig.org
root = true
[*] # 表示所有文件适用
charset = utf-8 # 设置文件字符集为 utf-8
indent_style = space # 缩进风格(tab | space)
indent_size = 2 # 缩进大小
end_of_line = lf # 控制换行类型(lf | cr | crlf)
trim_trailing_whitespace = true # 去除行尾的任意空白字符
insert_final_newline = true # 始终在文件末尾插入一个新行[*.md] # 表示仅 md 文件适用以下规则
max_line_length = off
trim_trailing_whitespace = false
VSCode 需要安装一个插件:EditorConfig for VS Code
{
"useTabs": false, // 使用空格缩进而非tab缩进"tabWidth": 2, // tab对应的空格数为2"printWidth": 80, // 每行字符长度为80"singleQuote": true, // 使用单引号"trailingComma": "none", // 多行输入末尾不添加逗号"semi": false // 语句末尾不加分号
}
3、创建.prettierignore 忽略文件
/dist/*
.local
.output.js
/node_modules/**
**/*.svg
**/*.sh
/public/*
4、VSCode 需要安装 prettier 的插件
5、VSCode 中的配置
6、测试 prettier 是否生效
"prettier": "prettier --write ."
1.3. 使用 ESLint 检测
extends: ["plugin:vue/vue3-essential","eslint:recommended","@vue/typescript/recommended","@vue/prettier","@vue/prettier/@typescript-eslint",'plugin:prettier/recommended'
],
"eslint.lintTask.enable": true,
"eslint.alwaysShowStatus": true,
"eslint.validate": ["javascript","javascriptreact","typescript","typescriptreact"
],
"editor.codeActionsOnSave": {"source.fixAll.eslint": true
}
这里可以关闭警告