forked from nodejs/core-validate-commit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassisted-by-is-trailer.js
More file actions
49 lines (48 loc) · 1.33 KB
/
assisted-by-is-trailer.js
File metadata and controls
49 lines (48 loc) · 1.33 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
const id = 'assisted-by-is-trailer'
export default {
id,
meta: {
description: 'enforce that "Assisted-by:" lines are trailers',
recommended: true
},
defaults: {},
options: {},
validate: (context, rule) => {
const parsed = context.toJSON()
const lines = parsed.body.map((line, i) => [line, i])
const re = /^Assisted-by:/gi
const assisted = lines.filter(([line]) => re.test(line))
if (assisted.length !== 0) {
const firstAssisted = assisted[0]
const emptyLines = lines.filter(([text]) => text.trim().length === 0)
// There must be at least one empty line, and the last empty line must be
// above the first Assisted-by line.
const isTrailer = (emptyLines.length !== 0) &&
emptyLines.at(-1)[1] < firstAssisted[1]
if (isTrailer) {
context.report({
id,
message: 'Assisted-by is a trailer',
string: '',
level: 'pass'
})
} else {
context.report({
id,
message: 'Assisted-by must be a trailer',
string: firstAssisted[0],
line: firstAssisted[1],
column: 0,
level: 'fail'
})
}
} else {
context.report({
id,
message: 'no Assisted-by metadata',
string: '',
level: 'pass'
})
}
}
}