From 75dc6e24d5f61925d4f2c7cd8282d68e2b15488a Mon Sep 17 00:00:00 2001 From: mizdra Date: Sat, 28 Sep 2024 17:49:51 +0900 Subject: [PATCH] use `util.stripVTControlCharacters` instead of `strip-ansi` --- e2e-test/import-as-esm-from-esm/index.test.ts | 4 ++-- package.json | 1 - pnpm-lock.yaml | 3 --- src/action/print-result-details.ts | 4 ++-- src/formatter/format-by-files.test.ts | 4 ++-- src/formatter/format-by-rules.test.ts | 6 +++--- 6 files changed, 9 insertions(+), 13 deletions(-) diff --git a/e2e-test/import-as-esm-from-esm/index.test.ts b/e2e-test/import-as-esm-from-esm/index.test.ts index d782faf8..3604b1ae 100644 --- a/e2e-test/import-as-esm-from-esm/index.test.ts +++ b/e2e-test/import-as-esm-from-esm/index.test.ts @@ -1,8 +1,8 @@ import { afterEach, expect, test } from 'vitest'; -import stripAnsi from 'strip-ansi'; import { createIFF } from '../../src/test-util/fixtures.js'; import dedent from 'dedent'; import { readFile } from 'fs/promises'; +import { stripVTControlCharacters } from 'util'; const { Core, takeRuleStatistics } = await import('eslint-interactive'); @@ -39,7 +39,7 @@ test('Programmable API', async () => { }); const results = await core.lint(); - expect(stripAnsi(core.formatResultSummary(results))).toMatchSnapshot(); + expect(stripVTControlCharacters(core.formatResultSummary(results))).toMatchSnapshot(); const statistics = takeRuleStatistics(results); expect(statistics).toMatchSnapshot(); diff --git a/package.json b/package.json index 0e47ce06..03f48708 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,6 @@ "find-cache-dir": "^5.0.0", "is-installed-globally": "^1.0.0", "ora": "^7.0.1", - "strip-ansi": "^7.1.0", "table": "^6.8.1", "terminal-link": "^3.0.0", "yargs": "^17.7.2" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index cb7195fc..8156268a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -35,9 +35,6 @@ importers: ora: specifier: ^7.0.1 version: 7.0.1 - strip-ansi: - specifier: ^7.1.0 - version: 7.1.0 table: specifier: ^6.8.1 version: 6.8.1 diff --git a/src/action/print-result-details.ts b/src/action/print-result-details.ts index 7e63b756..38c70670 100644 --- a/src/action/print-result-details.ts +++ b/src/action/print-result-details.ts @@ -1,9 +1,9 @@ import { writeFile } from 'node:fs/promises'; import { join } from 'node:path'; +import { stripVTControlCharacters } from 'node:util'; import chalk from 'chalk'; import { Remote } from 'comlink'; import { ESLint } from 'eslint'; -import stripAnsi from 'strip-ansi'; import { pager } from '../cli/pager.js'; import { promptToInputDisplayMode } from '../cli/prompt.js'; import { SerializableCore } from '../core-worker.js'; @@ -23,7 +23,7 @@ export async function doPrintResultDetailsAction( await pager(formattedResultDetails); } else if (displayMode === 'writeToFile') { const filePath = join(getCacheDir(), 'lint-result-details.txt'); - await writeFile(filePath, stripAnsi(formattedResultDetails), 'utf8'); + await writeFile(filePath, stripVTControlCharacters(formattedResultDetails), 'utf8'); console.log(chalk.cyan(`Wrote to ${filePath}`)); } else { // eslint-disable-next-line @typescript-eslint/restrict-template-expressions diff --git a/src/formatter/format-by-files.test.ts b/src/formatter/format-by-files.test.ts index d15108aa..1bfd0db0 100644 --- a/src/formatter/format-by-files.test.ts +++ b/src/formatter/format-by-files.test.ts @@ -1,5 +1,5 @@ +import { stripVTControlCharacters } from 'node:util'; import { ESLint } from 'eslint'; -import stripAnsi from 'strip-ansi'; import { describe, expect, test } from 'vitest'; import { fakeLintResult, fakeLintMessage } from '../test-util/eslint.js'; import { formatByFiles } from './format-by-files.js'; @@ -23,7 +23,7 @@ describe('formatByFiles', () => { }), ]; const formattedText = formatByFiles(results); - expect(stripAnsi(formattedText)).toMatchInlineSnapshot(` + expect(stripVTControlCharacters(formattedText)).toMatchInlineSnapshot(` "- 2 files (1 file passed, 1 file failed) checked. - 3 problems (2 errors, 1 warning) found." `); diff --git a/src/formatter/format-by-rules.test.ts b/src/formatter/format-by-rules.test.ts index fff78e5b..4fe30964 100644 --- a/src/formatter/format-by-rules.test.ts +++ b/src/formatter/format-by-rules.test.ts @@ -1,6 +1,6 @@ /* eslint-disable no-irregular-whitespace */ +import { stripVTControlCharacters } from 'node:util'; import { ESLint } from 'eslint'; -import stripAnsi from 'strip-ansi'; import { describe, expect, test } from 'vitest'; import { fakeLintResult, fakeLintMessage, fakeFix, fakeSuggestions } from '../test-util/eslint.js'; import { formatByRules } from './format-by-rules.js'; @@ -28,7 +28,7 @@ describe('formatByRules', () => { }), ]; const formattedText = formatByRules(results); - expect(stripAnsi(formattedText)).toMatchInlineSnapshot(` + expect(stripVTControlCharacters(formattedText)).toMatchInlineSnapshot(` "╔════════╤═══════╤═════════╤════════════╤═════════════════╗ ║ Rule │ Error │ Warning │ is fixable │ has suggestions ║ ╟────────┼───────┼─────────┼────────────┼─────────────────╢ @@ -66,7 +66,7 @@ describe('formatByRules', () => { 'plugin/rule-c': { docs: { url: 'https://example.com/plugin/rule-c' } }, }, }); - expect(stripAnsi(formattedText)).toMatchInlineSnapshot(` + expect(stripVTControlCharacters(formattedText)).toMatchInlineSnapshot(` "╔═══════════════╤═══════╤═════════╤════════════╤═════════════════╗ ║ Rule │ Error │ Warning │ is fixable │ has suggestions ║ ╟───────────────┼───────┼─────────┼────────────┼─────────────────╢