forked from nodejs/core-validate-commit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformat.js
99 lines (83 loc) · 2.5 KB
/
format.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
'use strict'
const chalk = require('chalk')
const diff = require('./diff')
const info = require('./info')
const fail = chalk.red('✖')
function line(obj) {
return obj.lineNum ? obj.lineNum : ''
}
function rpad(str, max) {
const diff = max - str.length + 1
if (diff > 0) {
return `${str}${' '.repeat(diff)}`
}
return str
}
function getInfo(s) {
return rpad(info[s] || '', 40)
}
exports.default = (obj, commit) => {
const t = chalk.red(obj.code)
const lin = obj.lineNum
? chalk.grey(rpad(`${line(obj)}:0`, 6))
: rpad('', 6)
const i = getInfo(obj.code)
return ` ${fail} ${lin} ${i} ${t}`
}
exports.header = (commit) => {
return ` ${chalk.underline(commit.sha)}`
}
exports.ETITLETOOLONG = (obj, commit) => {
const t = chalk.red('ETITLETOOLONG')
const lin = chalk.grey(rpad(`${line(obj)}:50`, 6))
const str = obj.str
const i = getInfo('ETITLETOOLONG')
return ` ${fail} ${lin} ${i} ${t}
${diff.ETITLETOOLONG(str)}`
}
exports.EINVALIDSUBSYSTEM = (obj, commit) => {
const t = chalk.red('EINVALIDSUBSYSTEM')
const title = commit.title
const col = title.indexOf(obj.str)
const lin = chalk.grey(rpad(`${line(obj)}:${col}`, 6))
const str = obj.str
const i = getInfo('EINVALIDSUBSYSTEM')
return ` ${fail} ${lin} ${i} ${t}
${diff.EINVALIDSUBSYSTEM(str, title)}`
}
exports.ELINETOOLONG = (obj, commit) => {
const t = chalk.red('ELINETOOLONG')
const lin = chalk.grey(rpad(`${line(obj)}:72`, 6))
const str = obj.str
const i = getInfo('ELINETOOLONG')
return ` ${fail} ${lin} ${i} ${t}
${diff.ELINETOOLONG(str)}`
}
exports.EMISSINGPRURL = (obj, commit) => {
const t = chalk.red('EMISSINGPRURL')
const lin = chalk.grey(rpad('0:0', 6))
const i = getInfo('EMISSINGPRURL')
return ` ${fail} ${lin} ${i} ${t}`
}
exports.EINVALIDPRURL = (obj, commit) => {
const t = chalk.red('EINVALIDPRURL')
const lin = chalk.grey(rpad(`${line(obj)}:7`, 6))
const i = getInfo('EINVALIDPRURL')
const str = obj.str
return ` ${fail} ${lin} ${i} ${t}
${diff.EINVALIDPRURL(str)}`
}
exports.EINVALIDFIXESURL = (obj, commit) => {
const t = chalk.red('EINVALIDFIXESURL')
const lin = chalk.grey(rpad(`${line(obj)}:6`, 6))
const i = getInfo('EINVALIDFIXESURL')
const str = obj.str
return ` ${fail} ${lin} ${i} ${t}
${diff.EINVALIDFIXESURL(str)}`
}
exports.EMETAORDER = (obj, commit) => {
const t = chalk.red('EMETAORDER')
const lin = chalk.grey(rpad(`${line(obj)}:0`, 6))
const i = getInfo('EMETAORDER')
return ` ${fail} ${lin} ${i} ${t}`
}