This repository was archived by the owner on Jun 27, 2022. It is now read-only.
forked from nodejs/core-validate-commit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathline-length.js
61 lines (58 loc) · 1.38 KB
/
line-length.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
'use strict'
const id = 'line-length'
module.exports = {
id: id,
meta: {
description: 'enforce max length of lines in commit body',
recommended: true
},
defaults: {
length: 72
},
options: {
length: 72
},
validate: (context, rule) => {
const len = rule.options.length
const parsed = context.toJSON()
// release commits include the notable changes from the changelog
// in the commit message
if (parsed.release) {
context.report({
id: id,
message: 'skipping line-length for release commit',
string: '',
level: 'skip'
})
return
}
let failed = false
for (let i = 0; i < parsed.body.length; i++) {
const line = parsed.body[i]
// Skip quoted lines, e.g. for original commit messages of V8 backports.
if (line.startsWith(' ')) { continue }
// Skip lines with URLs.
if (/https?:\/\//.test(line)) { continue }
if (line.length > len) {
failed = true
context.report({
id: id,
message: `Line should be <= ${len} columns.`,
string: line,
maxLength: len,
line: i,
column: len,
level: 'fail'
})
}
}
if (!failed) {
context.report({
id: id,
message: 'line-lengths are valid',
string: '',
level: 'pass'
})
}
}
}