-
-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathutils.js
More file actions
53 lines (47 loc) · 1.39 KB
/
utils.js
File metadata and controls
53 lines (47 loc) · 1.39 KB
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
import { styleText } from 'node:util'
export const CHECK = styleText('green', '✔')
export const X = styleText('red', '✖')
export const WARN = styleText('yellow', '⚠')
export function rightPad (str, max) {
const diff = max - str.length + 1
if (diff > 0) {
return `${str}${' '.repeat(diff)}`
}
return str
}
export function leftPad (str, max) {
const diff = max - str.length + 1
if (diff > 0) {
return `${' '.repeat(diff)}${str}`
}
return str
}
export function header (sha, status) {
switch (status) {
case 'skip':
case 'pass': {
const suffix = status === 'skip' ? ' # SKIPPED' : ''
return `${CHECK} ${styleText('underline', sha)}${suffix}`
}
case 'fail':
return `${X} ${styleText('underline', sha)}`
}
}
export function describeRule (rule, max = 20) {
if (rule.meta && rule.meta.description) {
const desc = rule.meta.description
const title = leftPad(rule.id, max)
console.log(' %s %s', styleText('red', title), styleText('dim', desc))
}
}
export function describeSubsystem (subsystems, max = 20) {
if (subsystems) {
for (let sub = 0; sub < subsystems.length; sub = sub + 3) {
console.log('%s %s %s',
styleText('green', leftPad(subsystems[sub] || '', max)),
styleText('green', leftPad(subsystems[sub + 1] || '', max)),
styleText('green', leftPad(subsystems[sub + 2] || '', max))
)
}
}
}