Skip to content

Commit 5c2399e

Browse files
committed
feat: 添加提交校验及自动格式化文件。
1 parent 20954af commit 5c2399e

File tree

23 files changed

+2491
-316
lines changed

23 files changed

+2491
-316
lines changed

.husky/commit-msg

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env sh
2+
. "$(dirname -- "$0")/_/husky.sh"
3+
4+
npx --no-install commitlint --edit ""

.husky/common.sh

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/sh
2+
command_exists () {
3+
command -v "$1" >/dev/null 2>&1
4+
}
5+
6+
# Workaround for Windows 10, Git Bash and pnpm
7+
if command_exists winpty && test -t 1; then
8+
exec < /dev/tty
9+
fi

.husky/lintstagedrc.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
'*.{js,jsx,ts,tsx}': ['eslint --fix', 'prettier --write'],
3+
'{!(package)*.json,.!(browserslist)*rc}': ['prettier --write--parser json'],
4+
'package.json': ['prettier --write'],
5+
'*.vue': ['eslint --fix', 'prettier --write', 'stylelint --fix'],
6+
'*.{vue,css,scss,postcss,less}': ['stylelint --fix', 'prettier --write'],
7+
'*.md': ['prettier --write'],
8+
}

.husky/pre-commit

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env sh
2+
. "$(dirname -- "$0")/_/husky.sh"
3+
. "$(dirname -- "$0")/common.sh"
4+
5+
pnpm type-check
6+
pnpm lint:style
7+
pnpm link:format
8+
pnpm link:lint-staged

.stylelintrc.cjs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
module.exports = {
2+
// 注册 stylelint 的 prettier 插件
3+
plugins: ['stylelint-prettier'], // 继承一系列规则集合
4+
extends: [
5+
// standard 规则集合
6+
'stylelint-config-standard',
7+
// standard 规则集合的 scss 版本
8+
'stylelint-config-standard-scss',
9+
// 样式属性顺序规则
10+
'stylelint-config-recess-order',
11+
// 样式属性 vue 规则
12+
'stylelint-config-recommended-vue',
13+
// 接入 Prettier 规则
14+
'stylelint-config-prettier',
15+
'stylelint-prettier/recommended',
16+
],
17+
// 配置 rules
18+
rules: {
19+
// 开启 Prettier 自动格式化功能
20+
'prettier/prettier': true,
21+
},
22+
}

commitlint.config.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// eslint-disable-next-line no-undef
2+
module.exports = {
3+
// 忽略部分
4+
ignores: [(commit) => commit.includes('init')],
5+
// 继承的规则
6+
extends: ['@commitlint/config-conventional'],
7+
// 定义规则类型
8+
rules: {
9+
'body-leading-blank': [2, 'always'],
10+
'footer-leading-blank': [1, 'always'],
11+
'header-max-length': [2, 'always', 108],
12+
'subject-empty': [2, 'never'],
13+
'type-empty': [2, 'never'],
14+
// type 类型定义,表示 git 提交的 type 必须在以下类型范围内
15+
'type-enum': [
16+
2,
17+
'always',
18+
[
19+
'feat', // 新增feature
20+
'fix', // 修复bug
21+
'perf', // 优化相关,比如性能、体验的提升
22+
'style', // 仅仅修改了空格、格式缩进、逗号等等,不改变代码逻辑;
23+
'docs', // 仅仅修改了文档,比如README, CHANGELOG, CONTRIBUTE等等;
24+
'test', // 测试用例,包括单元测试、集成测试等
25+
'refactor', // 代码重构,没有加新功能或者修复bug
26+
'build',
27+
'ci',
28+
'chore', // 改变构建流程、或者增加依赖库、工具等
29+
'revert', // 回滚到上一个版本
30+
'wip',
31+
'workflow',
32+
'types',
33+
'release',
34+
],
35+
],
36+
},
37+
}

package.json

+17-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
"build-only": "vite build",
1414
"type-check": "vue-tsc --noEmit",
1515
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore",
16-
"format": "prettier --write src/"
16+
"link:format": "prettier --write src/",
17+
"link:lint-staged": "lint-staged -c ./.husky/lintstagedrc.js",
18+
"lint:style": "stylelint --fix \"src/**/*.{css,scss}\"",
19+
"prepare": "husky install"
1720
},
1821
"dependencies": {
1922
"@alova/scene-vue": "^1.0.4",
@@ -30,6 +33,8 @@
3033
"vue-router": "^4.1.6"
3134
},
3235
"devDependencies": {
36+
"@commitlint/cli": "^17.6.5",
37+
"@commitlint/config-conventional": "^17.6.5",
3338
"@iconify-json/ep": "^1.1.10",
3439
"@rushstack/eslint-patch": "^1.2.0",
3540
"@types/dompurify": "^3.0.2",
@@ -42,9 +47,20 @@
4247
"@vue/tsconfig": "^0.1.3",
4348
"eslint": "^8.40.0",
4449
"eslint-plugin-vue": "^9.11.0",
50+
"husky": "^8.0.3",
51+
"lint-staged": "^13.2.2",
4552
"npm-run-all": "^4.1.5",
53+
"postcss-html": "^1.5.0",
54+
"postcss-scss": "^4.0.6",
4655
"prettier": "^2.8.8",
4756
"sass": "^1.62.1",
57+
"stylelint": "^15.6.3",
58+
"stylelint-config-prettier": "^9.0.5",
59+
"stylelint-config-recess-order": "^4.0.0",
60+
"stylelint-config-recommended-vue": "^1.4.0",
61+
"stylelint-config-standard": "^33.0.0",
62+
"stylelint-config-standard-scss": "^9.0.0",
63+
"stylelint-prettier": "^3.0.0",
4864
"typescript": "~4.8.4",
4965
"unplugin-auto-import": "^0.15.3",
5066
"unplugin-icons": "^0.15.3",

0 commit comments

Comments
 (0)