forked from nodejs/core-validate-commit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformat-tap.js
74 lines (70 loc) · 1.62 KB
/
format-tap.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
export default function formatTap (t, context, msgs, validator) {
for (const m of msgs) {
switch (m.level) {
case 'pass': {
const a = m.string ? ` [${m.string}]` : ''
t.pass(`${m.id}: ${m.message}${a}`)
break
}
case 'skip':
t.skip(`${m.id}: ${m.message}`)
break
case 'fail':
onFail(context, m, validator, t)
break
}
}
}
function onFail (context, m, validator, t) {
switch (m.id) {
case 'line-length':
case 'title-length':
lengthFail(context, m, validator, t)
break
case 'subsystem':
subsystemFail(context, m, validator, t)
break
default:
defaultFail(context, m, validator, t)
break
}
}
function lengthFail (context, m, validator, t) {
const body = m.id === 'title-length'
? context.title
: context.body
t.fail(`${m.id}: ${m.message}`, {
found: m.string.length,
compare: '<=',
wanted: m.maxLength,
at: {
line: m.line || 0,
column: m.column || 0,
body
}
})
}
function subsystemFail (context, m, validator, t) {
t.fail(`${m.id}: ${m.message} (${m.string})`, {
found: m.string,
compare: 'indexOf() !== -1',
wanted: m.wanted || '',
at: {
line: m.line || 0,
column: m.column || 0,
body: m.title
}
})
}
function defaultFail (context, m, validator, t) {
t.fail(`${m.id}: ${m.message} (${m.string})`, {
found: m.string,
compare: Array.isArray(m.wanted) ? 'indexOf() !== -1' : '===',
wanted: m.wanted || '',
at: {
line: m.line || 0,
column: m.column || 0,
body: context.body
}
})
}