forked from nodejs/core-validate-commit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathline-length.js
57 lines (54 loc) · 1.16 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
'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
}
var failed = false
for (let i = 0; i < parsed.body.length; i++) {
const line = parsed.body[i]
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'
})
}
}
}