CMS项目搭建规范
一、代码规范
-
editorconfig配置 ->保证各个操作系统上IDE保持风格一致
不同编辑器保持相同的格式
.editorconfig
文件
# http://editorconfig.rog
root = true
[*] # 表示所有文件适用
charset = utf-8 # 设置文件字符集为 utf-8
indent_style = space # 缩进风格 (tab | space)
indent_size = 2 # 缩进大小
end_of_line = lf # 控制换行类型(lf | cr | crlf)
trime_tailing_whitespace = true # 去除行首的任意空白字符
insert_final_newline = true # 始终在文件末尾插入一个新行
[*.md] # 表示仅 md 文件适用以下规则
max_line_length = off
trim_trailing_whitespace = false
1.2 prettier配置
yarn add prettier -D
.prettier
文件
{
"useTabs": false,
"tabWidth": 2,
"printWidth": 80,
"singleQuote": true,
"trailingComma": "none",
"semi": false
}
"useTabs": false,
//使用tab缩进还是空格缩进,选false"tabWidth": 2,
//tab时空格的情况下,是几个空格,选择2个"printWidth": 80,
//当行的字符的长度,推荐80"singleQuote": true,
//使用单引号还是双引号,选择true,单引号"trailingComma": "none",
//在多行输入的尾逗号是否添加,设置为node"semi": false
//语句末尾是否要加分号,默认值为true,选择false不加
.prettierignore
忽略格式化文件配置,需要安装prettier插件才可以
/dist/*
.local
.output.js
/node_modules/**
**/*.svg
**/*.sh
/public/*
所有文件统一格式化package.json
脚本,一次对所有文件进行修复
"prettier": "prettier --write ."
1.3使用ESLint检测
'plugin:prettier/recommended'
1.4git husky和eslint
提交时进行检测
npx husky-init && npm install
1.5提交信息规范
yarn add commitizen -D
yarn commitizen init cz-conventional-changelog --save-dev --save-exact
需要先将文件添加到暂缓区,之后使用cz进行格式化提交,但是依然无法阻止错误的commit提交信息,配置强制不符合不提交
1.5.1安装插件
yarn add @commitlint/config-conventional @commitlint/cli -D
1.5.2.添加配置文件commitlint.config.js
module.exports = {
extends: ['@commitlint/config-conventional']
}
生成msg检测文件
yarn husky add .husky/commit-msg "npx --no-install commitlint --edit $1"
yarn husky add .husky/commit-msg "yarn commitlint --edit $1"
1.5.3.配置package.json
,使用yarn commit
来运行cz
"commit": "git add . && cz" //直接使用yarn commit即可,后不使用git commit -m msg