-
-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathco-authored-by-is-trailer.js
More file actions
49 lines (48 loc) · 1.36 KB
/
co-authored-by-is-trailer.js
File metadata and controls
49 lines (48 loc) · 1.36 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 = 'co-authored-by-is-trailer'
export default {
id,
meta: {
description: 'enforce that "Co-authored-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 = /^Co-authored-by:/gi
const coauthors = lines.filter(([line]) => re.test(line))
if (coauthors.length !== 0) {
const firstCoauthor = coauthors[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 Co-authored-by line.
const isTrailer = (emptyLines.length !== 0) &&
emptyLines.at(-1)[1] < firstCoauthor[1]
if (isTrailer) {
context.report({
id,
message: 'Co-authored-by is a trailer',
string: '',
level: 'pass'
})
} else {
context.report({
id,
message: 'Co-authored-by must be a trailer',
string: firstCoauthor[0],
line: firstCoauthor[1],
column: 0,
level: 'fail'
})
}
} else {
context.report({
id,
message: 'no Co-authored-by metadata',
string: '',
level: 'pass'
})
}
}
}