Skip to content

Commit 55d770d

Browse files
committed
Improve readability of console output
1 parent fa96fa8 commit 55d770d

3 files changed

Lines changed: 35 additions & 19 deletions

File tree

commands/lint.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// SPDX-FileCopyrightText: Copyright 2023 Edwin Kofler
33
import * as path from 'node:path'
44
import * as fs from 'node:fs/promises'
5-
import * as readline from 'node:readline/promises'
5+
import * as inquirer from '@inquirer/prompts'
66
import { styleText } from 'node:util'
77
import os from 'node:os'
88
import { fileExists, pkgRoot } from '#common'
@@ -273,7 +273,7 @@ async function fixFromFile(
273273
}
274274
}
275275

276-
console.info(`[EVAL] ${fixId}: Found issue`)
276+
console.info(`[EVAL] ${fixId}`)
277277
if (Array.isArray(issue.message)) {
278278
for (const message of issue.message) {
279279
console.info(` -> ${message}`)
@@ -294,15 +294,20 @@ async function fixFromFile(
294294
if (options.yes) {
295295
shouldRunFix = true
296296
} else {
297-
const rl = readline.createInterface({
298-
input: process.stdin,
299-
output: process.stdout,
300-
})
301-
const input = await rl.question(
302-
`Would you like to fix this issue? (y/n): `,
303-
)
304-
rl.close()
305-
shouldRunFix = yn(input)
297+
try {
298+
shouldRunFix = await inquirer.confirm({
299+
message: 'Would you like to fix this issue?',
300+
default: true,
301+
}, { clearPromptOnDone: true })
302+
} catch (err) {
303+
if (err.name === 'ExitPromptError') {
304+
printWithTips(`[${styleText('red', 'FAIL')}] ${fixId}`, [
305+
'Failed because the user exited the prompt',
306+
])
307+
Deno.exit(1)
308+
}
309+
throw err
310+
}
306311
}
307312

308313
if (shouldRunFix) {

config/common.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,28 @@ export async function* filesMustHaveContent(
4545
const content = await fs.readFile(file, 'utf-8')
4646
if (content !== expectedContent) {
4747
yield {
48-
message:
49-
` -> Expected file "${file}" to have content:\n---\n${expectedContent}\n---\n -> But, the file has content:\n---\n${content}\n---\n`,
48+
message: dedent`
49+
-> Expected file "${file}" to have content:
50+
${'='.repeat(80)}
51+
${expectedContent}
52+
${'='.repeat(80)}
53+
-> But, the file has content:
54+
${'='.repeat(80)}
55+
${content}
56+
${'='.repeat(80)}
57+
`,
5058
fix: () => fs.writeFile(file, expectedContent),
5159
}
5260
}
5361
} else {
5462
yield {
55-
message:
56-
` -> Expected file "${file}" to exist and have content:\n---\n${expectedContent}\n---\n -> But, the file does not exist`,
63+
message: dedent`
64+
-> Expected file "${file}" to exist and have content:
65+
${'='.repeat(80)}
66+
${expectedContent}
67+
${'='.repeat(80)}
68+
-> But, the file does not exist
69+
`,
5770
fix: () => fs.writeFile(file, expectedContent),
5871
}
5972
}
@@ -88,8 +101,7 @@ export async function* filesMustHaveShape(
88101
.replaceAll(/\n-(?!\-)/g, '\n' + styleText('red', '-'))
89102

90103
yield {
91-
message: ' ' +
92-
dedent`
104+
message: dedent`
93105
-> Expected file "${file}" to have the correct shape:
94106
${'='.repeat(80)}
95107
${patch.replaceAll('\n', '\n' + '\t'.repeat(5))}${'='.repeat(80)}

config/lint-rules/400-ecosystem/nodejs/tsconfig.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ export const issues: Issues = async function* issues({ project }) {
5959
.replaceAll(/\n-(?!\-)/g, '\n' + styleText('red', '-'))
6060

6161
yield {
62-
message: ' ' +
63-
dedent`
62+
message: dedent`
6463
-> Expected file "${configFile}" to have the correct shape:
6564
${'='.repeat(80)}
6665
${patch.replaceAll('\n', '\n' + '\t'.repeat(5))}${'='.repeat(80)}

0 commit comments

Comments
 (0)