Skip to content

Commit

Permalink
Merge pull request #378 from mizdra/use-util-pkg-instead-of-strip-ansi
Browse files Browse the repository at this point in the history
Use `util.stripVTControlCharacters` instead of `strip-ansi`
  • Loading branch information
mizdra authored Sep 28, 2024
2 parents d2090b6 + 75dc6e2 commit 48c9f39
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 13 deletions.
4 changes: 2 additions & 2 deletions e2e-test/import-as-esm-from-esm/index.test.ts
Original file line number Diff line number Diff line change
@@ -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');

Expand Down Expand Up @@ -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();

Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 0 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/action/print-result-details.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/formatter/format-by-files.test.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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."
`);
Expand Down
6 changes: 3 additions & 3 deletions src/formatter/format-by-rules.test.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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 ║
╟────────┼───────┼─────────┼────────────┼─────────────────╢
Expand Down Expand Up @@ -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 ║
╟───────────────┼───────┼─────────┼────────────┼─────────────────╢
Expand Down

0 comments on commit 48c9f39

Please sign in to comment.