-
Notifications
You must be signed in to change notification settings - Fork 0
/
commitlint.config.js
114 lines (110 loc) · 3.64 KB
/
commitlint.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// @ts-check
/**
* @typedef {object} Parsed
* @property {?string} emoji
* @property {?string} type
* @property {?string} scope
* @property {?string} subject
*/
const emojiEnum = /** @type {const} */ ([
2,
"always",
{
"🎉": ["init", "Project initialization"],
"✨": ["feat", "Adding new features"],
"🐞": ["fix", "Fixing bugs"],
"📃": ["docs", "Modify documentation only"],
"🌈": [
"style",
"Only the spaces, formatting indentation, commas, etc. were changed, not the code logic",
],
"🦄": ["refactor", "Code refactoring, no new features added or bugs fixed"],
"🎈": ["perf", "Optimization-related, such as improving performance, experience"],
"🧪": ["test", "Adding or modifying test cases"],
"🔧": [
"build",
"Dependency-related content, such as Webpack, Vite, Rollup, npm, package.json, etc.",
],
"🐎": ["ci", "CI configuration related, e.g. changes to k8s, docker configuration files"],
"🐳": ["chore", "Other modifications, e.g. modify the configuration file"],
"↩": ["revert", "Rollback to previous version"],
},
]);
/** @satisfies {import("@commitlint/types").UserConfig} */
const config = {
parserPreset: {
parserOpts: {
headerPattern:
/^(?<emoji>\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff]) (?<type>\w+)(?:\((?<scope>.*)\))?!?: (?<subject>(?:(?!#).)*(?:(?!\s).))$/,
headerCorrespondence: ["emoji", "type", "scope", "subject"],
},
},
plugins: [
{
rules: {
"header-match-git-commit-message-with-emoji-pattern": (parsed) => {
const { emoji, scope, subject, type } = /** @type {Parsed} */ (
/** @type {unknown} */ (parsed)
);
if (emoji === null && type === null && scope === null && subject === null)
return [
false,
"header must be in format '<emoji> <type>(<scope>?): <subject>', e.g:\n" +
" - 🎉 init: Initial commit\n" +
" - ✨ feat(assertions): Add assertions\n" +
" ",
];
return [true, ""];
},
"emoji-enum": (parsed, _, value) => {
const { emoji } = /** @type {Parsed} */ (/** @type {unknown} */ (parsed));
const emojisObject = /** @type {typeof emojiEnum[2]} */ (/** @type {unknown} */ (value));
if (emoji && !Object.keys(emojisObject).includes(emoji)) {
return [
false,
"emoji must be one of:\n" +
Object.entries(emojisObject)
.map(([emoji, [type, description]]) => ` ${emoji} ${type} - ${description}`)
.join("\n") +
"\n ",
];
}
return [true, ""];
},
},
},
],
rules: {
"header-match-git-commit-message-with-emoji-pattern": [2, "always"],
"body-leading-blank": [2, "always"],
"footer-leading-blank": [2, "always"],
"header-max-length": [2, "always", 72],
"scope-case": [2, "always", ["lower-case", "upper-case"]],
"subject-case": [2, "always", "sentence-case"],
"subject-empty": [2, "never"],
"subject-exclamation-mark": [2, "never"],
"subject-full-stop": [2, "never", "."],
"emoji-enum": emojiEnum,
"type-case": [2, "always", "lower-case"],
"type-empty": [2, "never"],
"type-enum": [
2,
"always",
[
"init",
"feat",
"fix",
"docs",
"style",
"refactor",
"perf",
"test",
"build",
"ci",
"chore",
"revert",
],
],
},
};
export default config;