Repository navigation
Expand file tree
/
Copy pathcommitlint.config.ts
More file actions
175 lines (167 loc) · 5.48 KB
/
Copy pathcommitlint.config.ts
File metadata and controls
175 lines (167 loc) · 5.48 KB
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import type { UserConfig } from "@commitlint/types";
import { RuleConfigSeverity } from "@commitlint/types";
const hasBreakingWord = (value: string): boolean => {
return /break(ing)?/i.test(value);
};
const hasEmoji = (value: string): boolean => {
return /\p{Emoji_Presentation}/u.test(value);
};
const hasExclamationMark = (type: string, header: string): boolean => {
return new RegExp(`${type}(\\(.*\\))?!:`).test(header);
};
const Configuration: UserConfig = {
extends: ["@commitlint/config-conventional"],
parserPreset: "conventional-changelog-conventionalcommits",
formatter: "@commitlint/format",
plugins: [
{
rules: {
"check-breaking-change": ({ subject, body, footer, type, header }) => {
const has_break_word_footer = hasBreakingWord(footer || "");
const has_break_word_subject = hasBreakingWord(subject || "");
const has_break_word_body = hasBreakingWord(body || "");
const type_includes_exclamation_mark = hasExclamationMark(
type || "",
header || ""
);
if (
(type_includes_exclamation_mark || has_break_word_subject) &&
!body
) {
return [
false,
"Breaking change requires a body — describe what changed and why",
];
}
if (
(has_break_word_footer ||
has_break_word_subject ||
has_break_word_body) &&
!type_includes_exclamation_mark
) {
return [
false,
`Breaking change detected — use "!" after type e.g. ${type}!: ${subject}`,
];
}
return [true, ""];
},
"subject-check-noemoji": ({ subject }) => {
// Custom rule implementation
const has_emoji_subject = hasEmoji(subject || "");
if (has_emoji_subject) {
return [false, "subject cannot contain emojis"];
}
return [true, ""];
},
},
},
"commitlint-plugin-tense",
],
rules: {
// -- Throw error when emoji detects
"subject-check-noemoji": [2, "always"],
// -- Throw error if breaking change but not specified properly
"check-breaking-change": [2, "always"],
"tense/subject-tense": [2, "always"],
"type-enum": [
RuleConfigSeverity.Error,
"always",
[
"feat",
"chore",
"fix",
"perf",
"test",
"docs",
"style",
"build",
"refactor",
"ci",
],
],
"type-case": [RuleConfigSeverity.Error, "always", ["lower-case"]],
"header-trim": [RuleConfigSeverity.Error, "never"],
"subject-case": [RuleConfigSeverity.Error, "always", ["lower-case"]],
"subject-empty": [RuleConfigSeverity.Error, "never"],
"subject-max-length": [RuleConfigSeverity.Error, "always", 70],
"scope-case": [RuleConfigSeverity.Error, "always", ["lower-case"]],
"scope-delimiter-style": [RuleConfigSeverity.Error, "always", [","]],
"body-case": [RuleConfigSeverity.Error, "always", ["sentence-case"]],
"body-leading-blank": [RuleConfigSeverity.Error, "always"],
},
prompt: {
questions: {
type: {
description: "Select the type of change that you're committing",
enum: {
feat: {
description: "A new feature",
title: "Features",
emoji: "✨",
},
fix: {
description: "A bug fix",
title: "Bug Fixes",
emoji: "🐛",
},
docs: {
description: "Documentation only changes",
title: "Documentation",
emoji: "📚",
},
style: {
description:
"Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)",
title: "Styles",
emoji: "💎",
},
refactor: {
description:
"A code change that neither fixes a bug nor adds a feature",
title: "Code Refactoring",
emoji: "📦",
},
perf: {
description: "A code change that improves performance",
title: "Performance Improvements",
emoji: "🚀",
},
test: {
description: "Adding missing tests or correcting existing tests",
title: "Tests",
emoji: "🚨",
},
build: {
description:
"Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)",
title: "Builds",
emoji: "🛠",
},
ci: {
description:
"Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)",
title: "Continuous Integrations",
emoji: "⚙️",
},
chore: {
description: "Other changes that don't modify src or test files",
title: "Chores",
emoji: "♻️",
},
isBreaking: {
description: "Are there any breaking changes?",
},
breakingBody: {
description:
"A BREAKING CHANGE commit requires a body. Please enter a longer description of the commit itself",
},
breaking: {
description: "Describe the breaking changes",
},
},
},
},
},
};
export default Configuration;