-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.ts
More file actions
114 lines (105 loc) · 2.87 KB
/
config.ts
File metadata and controls
114 lines (105 loc) · 2.87 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
import {
Commit,
LintOptions,
Plugin,
QualifiedRules,
Rule,
RuleConfigCondition,
} from "@commitlint/types";
declare module "@commitlint/types" {
interface Commit {
ticket: string | null;
}
}
const anyEmojiWithSpaceAfter =
/^([\u{1f300}-\u{1f5ff}\u{1f900}-\u{1f9ff}\u{1f600}-\u{1f64f}\u{1f680}-\u{1f6ff}\u{2600}-\u{26ff}\u{2700}-\u{27bf}\u{1f1e6}-\u{1f1ff}\u{1f191}-\u{1f251}\u{1f004}\u{1f0cf}\u{1f170}-\u{1f171}\u{1f17e}-\u{1f17f}\u{1f18e}\u{3030}\u{2b50}\u{2b55}\u{2934}-\u{2935}\u{2b05}-\u{2b07}\u{2b1b}-\u{2b1c}\u{3297}\u{3299}\u{303d}\u{00a9}\u{00ae}\u{2122}\u{23f3}\u{24c2}\u{23e9}-\u{23ef}\u{25b6}\u{23f8}-\u{23fa}](?:[\u{fe00}-\u{fe0f}])?)\s/u;
const optionalPlanableTicketWithSpaceAfter = /(?:\[(.+)\]\s)?/;
const subjectThatDoesNotStartsWithBracket =
/([^[\d\s][a-zA-Z](?:(?!\[P-\d|SER-\d).)*)$/;
const headerMatchPlanablePattern: Rule = (parsed: Commit) => {
const { type, ticket, subject } = parsed;
if (type === null && ticket === null && subject === null) {
return [
false,
"header must be in format '🌈 [P-11] Replace footer' or '🚧 Replace footer'",
];
}
return [true];
};
const ticketPattern: Rule = (parsed: Commit) => {
const planableTicket = /(^P-\d+$)|(^SER-\d+$)/;
const { ticket } = parsed;
if (ticket) {
if (!planableTicket.test(ticket)) {
return [
false,
"ticket must be in format of a valid Linear issue, for example: [P-11] or [SER-123]",
];
}
}
return [true];
};
const explainedTypeEnum: Rule<string[]> = (
parsed: Commit,
_when?: RuleConfigCondition,
expectedValue?: string[]
) => {
const { type } = parsed;
if (type && expectedValue && !expectedValue.includes(type)) {
return [false, `type must be one of ${expectedValue}.`];
}
return [true];
};
export const planablePlugin: Plugin = {
rules: {
"header-match-planable-pattern": headerMatchPlanablePattern,
"ticket-match-pattern": ticketPattern,
"explained-type-enum": explainedTypeEnum,
},
};
export const parserPreset: LintOptions = {
parserOpts: {
headerPattern: new RegExp(
anyEmojiWithSpaceAfter.source +
optionalPlanableTicketWithSpaceAfter.source +
subjectThatDoesNotStartsWithBracket.source,
"u"
),
headerCorrespondence: ["type", "ticket", "subject"],
},
plugins: {
planable: planablePlugin,
},
};
export const rules: QualifiedRules = {
"header-match-planable-pattern": [2, "always"],
"ticket-match-pattern": [2, "always"],
"explained-type-enum": [
2,
"always",
[
"✅",
"🚧",
"📓",
"🐞",
"🚨",
"👌",
"⚡️",
"⚡",
"⬆️",
"⬇️",
"✏️",
"♻️",
"⭐️",
"⭐",
"✨",
"🛠️",
"🛠",
"📦",
"🌈",
"🔀",
"🤖",
],
],
"subject-case": [2, "always", "sentence-case"],
};