-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommitlint.config.cjs
More file actions
69 lines (62 loc) · 2.11 KB
/
Copy pathcommitlint.config.cjs
File metadata and controls
69 lines (62 loc) · 2.11 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
const linearFooterLinePattern =
/^(?:[Cc]lose|[Cc]loses|[Cc]losed|[Cc]losing|[Ff]ix|[Ff]ixes|[Ff]ixed|[Ff]ixing|[Rr]esolve|[Rr]esolves|[Rr]esolved|[Rr]esolving|[Cc]omplete|[Cc]ompletes|[Cc]ompleted|[Cc]ompleting|[Ii]mplements|[Ii]mplemented|[Ii]mplementing|[Rr]ef|[Rr]efs|[Rr]eferences|[Pp]art of|[Cc]ontributes to)\s+DUB-\d+(?:,\s*DUB-\d+)*$/;
const conventionalTrailerPattern =
/^(?:BREAKING[ -]CHANGE|[A-Za-z][A-Za-z-]*)(?: #\d+)?: .+$/;
module.exports = {
extends: ['@commitlint/config-conventional'],
plugins: [
{
rules: {
'linear-footer': (parsed) => [
hasLinearFooter(parsed.raw ?? ''),
'commit footer must include exactly one DUB Linear magic-word line like "Completes DUB-1"',
],
},
},
],
rules: {
'body-leading-blank': [2, 'always'],
'footer-leading-blank': [2, 'always'],
'header-max-length': [2, 'always', 100],
'linear-footer': [2, 'always'],
'subject-empty': [2, 'never'],
'type-empty': [2, 'never'],
},
};
function hasLinearFooter(raw) {
const normalized = raw.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
const matchingLinearLines = normalized
.split('\n')
.map((line) => line.trim())
.filter((line) => linearFooterLinePattern.test(line));
const footerBlock =
normalized
.trim()
.split(/\n{2,}/)
.at(-1) ?? '';
const lines = footerBlock
.split('\n')
.filter((line) => line.trim().length > 0);
let hasLinearLine = false;
let previousLineAllowsContinuation = false;
const hasOnlyValidFooterLines = lines.every((line) => {
if (/^[\t ]+/.test(line)) {
return previousLineAllowsContinuation;
}
const trimmedLine = line.trim();
if (linearFooterLinePattern.test(trimmedLine)) {
hasLinearLine = true;
previousLineAllowsContinuation = false;
return true;
}
if (conventionalTrailerPattern.test(trimmedLine)) {
previousLineAllowsContinuation = true;
return true;
}
previousLineAllowsContinuation = false;
return false;
});
return (
hasLinearLine && hasOnlyValidFooterLines && matchingLinearLines.length === 1
);
}