forked from nodejs/core-validate-commit
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetadata-end.js
47 lines (43 loc) · 983 Bytes
/
metadata-end.js
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
'use strict'
const id = 'metadata-end'
module.exports = {
id: id,
meta: {
description: 'enforce that metadata is at the end of commit messages',
recommended: true
},
defaults: {},
options: {},
validate: (context, rule) => {
const parsed = context.toJSON()
const body = parsed.body
const end = parsed.metadata.end
if (end < body.length) {
const extra = body.slice(end + 1)
let lineNum = end + 1
for (let i = 0; i < extra.length; i++) {
if (extra[i]) {
lineNum += i
break
}
}
if (lineNum !== end + 1) {
context.report({
id: id,
message: 'commit metadata at end of message',
string: body[lineNum],
line: lineNum,
column: 0,
level: 'fail'
})
return
}
}
context.report({
id: id,
message: 'metadata is at end of message',
string: '',
level: 'pass'
})
}
}