From 80f98de4c507011f13204d434546daa93d37db01 Mon Sep 17 00:00:00 2001 From: Aaron Moat <2937187+AaronMoat@users.noreply.github.com> Date: Wed, 10 Jan 2024 11:24:38 +1100 Subject: [PATCH] Clean up double message --- .../internalLints/refreshIgnoreFiles.test.ts | 4 +-- .../lint/internalLints/refreshIgnoreFiles.ts | 32 +++++++++---------- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/cli/lint/internalLints/refreshIgnoreFiles.test.ts b/src/cli/lint/internalLints/refreshIgnoreFiles.test.ts index c9937a5a8..44b748ec0 100644 --- a/src/cli/lint/internalLints/refreshIgnoreFiles.test.ts +++ b/src/cli/lint/internalLints/refreshIgnoreFiles.test.ts @@ -94,8 +94,8 @@ describe('refreshIgnoreFiles', () => { }); expect(`\n${stdout()}`).toBe(` -The .eslintignore file is out of date. Run pnpm exec skuba format to update it. refresh-ignore-files -The .gitignore file is out of date. Run pnpm exec skuba format to update it. refresh-ignore-files +The .eslintignore file is out of date. Run \`pnpm exec skuba format\` to update it. refresh-ignore-files +The .gitignore file is out of date. Run \`pnpm exec skuba format\` to update it. refresh-ignore-files `); expect(writeFile).not.toHaveBeenCalled(); diff --git a/src/cli/lint/internalLints/refreshIgnoreFiles.ts b/src/cli/lint/internalLints/refreshIgnoreFiles.ts index 1171d54a8..6de93d145 100644 --- a/src/cli/lint/internalLints/refreshIgnoreFiles.ts +++ b/src/cli/lint/internalLints/refreshIgnoreFiles.ts @@ -2,6 +2,7 @@ import path from 'path'; import { inspect } from 'util'; import { writeFile } from 'fs-extra'; +import stripAnsi from 'strip-ansi'; import type { Logger } from '../../../utils/logging'; import { detectPackageManager } from '../../../utils/packageManager'; @@ -53,9 +54,8 @@ export const refreshIgnoreFiles = async ( await writeFile(filepath, data); return { needsChange: false, - msg: `Refreshed ${logger.bold(filename)}. ${logger.dim( - 'refresh-ignore-files', - )}`, + msg: `Refreshed ${logger.bold(filename)}.`, + filename, }; } @@ -66,13 +66,12 @@ export const refreshIgnoreFiles = async ( needsChange: true, msg: `The ${logger.bold( filename, - )} file is out of date. Run ${logger.bold( + )} file is out of date. Run \`${logger.bold( packageManager.exec, 'skuba', 'format', - )} to update it. ${logger.dim('refresh-ignore-files')}`, + )}\` to update it.`, filename, - annotationMessage: `The ${filename} file is out of date. Run \`${packageManager.exec} skuba format\` to update it.`, }; } @@ -86,7 +85,7 @@ export const refreshIgnoreFiles = async ( // Log after for reproducible test output ordering results.forEach((result) => { if (result.msg) { - logger.warn(result.msg); + logger.warn(result.msg, logger.dim('refresh-ignore-files')); } }); @@ -95,16 +94,15 @@ export const refreshIgnoreFiles = async ( return { ok: !anyNeedChanging, fixable: anyNeedChanging, - annotations: results.flatMap( - ({ needsChange, filename, annotationMessage }) => - needsChange && annotationMessage - ? [ - { - path: filename, - message: annotationMessage, - }, - ] - : [], + annotations: results.flatMap(({ needsChange, filename, msg }) => + needsChange && msg + ? [ + { + path: filename, + message: stripAnsi(msg), + }, + ] + : [], ), }; };