-
Notifications
You must be signed in to change notification settings - Fork 390
Expand file tree
/
Copy pathcommitlint.config.js
More file actions
64 lines (55 loc) · 1.82 KB
/
commitlint.config.js
File metadata and controls
64 lines (55 loc) · 1.82 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
/**
* Custom commitlint configuration for JIRA-style commit messages.
* Enforces format: NAS-12345: commit message
*
* Replaces deprecated commitlint-config-jira and commitlint-plugin-jira-rules packages
* with custom rules using commitlint's built-in functionality.
*/
// Custom parser to extract JIRA ticket from commit message
const parserPreset = {
parserOpts: {
headerPattern: /^(NAS-\d+):\s(.+)$/,
headerCorrespondence: ['type', 'subject'],
},
};
export default {
parserPreset,
rules: {
// Enforce that the commit message matches the pattern: NAS-<number>: <message>
'header-match-team-pattern': [
2,
'always',
'Commit message must match format: NAS-<issue-number>: <description>\nExample: NAS-12345: Add new feature'
],
// Ensure the header is not too long
'header-max-length': [2, 'always', 120],
// Ensure there is a subject (message after the colon)
'subject-empty': [2, 'never'],
// Ensure subject doesn't end with a period
'subject-full-stop': [2, 'never', '.'],
// Type (which contains the JIRA ticket) should not be empty
'type-empty': [2, 'never'],
// Type should match NAS-<digits> pattern (1-6 digits for task ID under 10 chars total)
'type-enum': [0], // Disable enum check
'type-case': [0], // Disable case check
},
plugins: [
{
rules: {
'header-match-team-pattern': (parsed) => {
const { header } = parsed;
const pattern = /^NAS-\d{1,6}:\s.+$/;
if (!pattern.test(header)) {
return [
false,
'Commit message must match format: NAS-<issue-number>: <description>\n' +
'Example: NAS-12345: Add new feature\n' +
'Your message: ' + header
];
}
return [true];
},
},
},
],
};