From 7e67e43061b1e491c398d3cc451ffe3deea61822 Mon Sep 17 00:00:00 2001 From: ADTC Date: Mon, 9 Oct 2023 07:40:28 +0800 Subject: [PATCH] Show `(unchanged)` keyword for accessibility in CLI `--write` (#15467) --- changelog_unreleased/cli/15467.md | 19 +++++++ src/cli/format.js | 2 +- .../line-after-filepath-with-errors.js.snap | 2 +- .../__tests__/__snapshots__/write.js.snap | 2 +- tests/integration/__tests__/cache.js | 56 +++++++++---------- 5 files changed, 50 insertions(+), 31 deletions(-) create mode 100644 changelog_unreleased/cli/15467.md diff --git a/changelog_unreleased/cli/15467.md b/changelog_unreleased/cli/15467.md new file mode 100644 index 000000000..b69c49842 --- /dev/null +++ b/changelog_unreleased/cli/15467.md @@ -0,0 +1,19 @@ +#### Show `(unchanged)` keyword for accessibility in CLI `--write` (#15467 by @ADTC) + +Previously, the only distinction between a changed file and an unchanged file was the grey color of the file name. In the example below, we can't distinguish between `a.js` and `b.js` as the color is missing. This issue is fixed by adding the `(unchanged)` keyword which makes the distinction accessible without color. + + +```sh +# Input +prettier --write . + +# Prettier stable +a.js 0ms +b.js 0ms +c.js 0ms (cached) + +# Prettier main +a.js 0ms +b.js 0ms (unchanged) +c.js 0ms (unchanged) (cached) +``` diff --git a/src/cli/format.js b/src/cli/format.js index 0192b8326..9b4d6a2d2 100644 --- a/src/cli/format.js +++ b/src/cli/format.js @@ -437,7 +437,7 @@ async function formatFiles(context) { } else if (!context.argv.check && !context.argv.listDifferent) { const message = `${chalk.grey(fileNameToDisplay)} ${ Date.now() - start - }ms`; + }ms (unchanged)`; if (isCacheExists) { context.logger.log(`${message} (cached)`); } else { diff --git a/tests/integration/__tests__/__snapshots__/line-after-filepath-with-errors.js.snap b/tests/integration/__tests__/__snapshots__/line-after-filepath-with-errors.js.snap index f571b2fe4..54cd7779d 100644 --- a/tests/integration/__tests__/__snapshots__/line-after-filepath-with-errors.js.snap +++ b/tests/integration/__tests__/__snapshots__/line-after-filepath-with-errors.js.snap @@ -83,7 +83,7 @@ invalid-2.unknown [[called readline.clearLine(process.stdout)]] valid-1.js [[called readline.clearLine(process.stdout)]] -valid-1.js 0ms" +valid-1.js 0ms (unchanged)" `; exports[`Line breaking after filepath with errors (write) 1`] = `[]`; diff --git a/tests/integration/__tests__/__snapshots__/write.js.snap b/tests/integration/__tests__/__snapshots__/write.js.snap index 7a5d44291..15a6f0caa 100644 --- a/tests/integration/__tests__/__snapshots__/write.js.snap +++ b/tests/integration/__tests__/__snapshots__/write.js.snap @@ -2,7 +2,7 @@ exports[`do not write file with --write + formatted file (stderr) 1`] = `""`; -exports[`do not write file with --write + formatted file (stdout) 1`] = `"formatted.js 0ms"`; +exports[`do not write file with --write + formatted file (stdout) 1`] = `"formatted.js 0ms (unchanged)"`; exports[`do not write file with --write + invalid file (stderr) 1`] = ` "[error] invalid.js: SyntaxError: Unexpected token (1:17) diff --git a/tests/integration/__tests__/cache.js b/tests/integration/__tests__/cache.js index f02df5439..34363b096 100644 --- a/tests/integration/__tests__/cache.js +++ b/tests/integration/__tests__/cache.js @@ -133,7 +133,7 @@ describe("--cache option", () => { expect(firstStdout.split("\n")).toEqual( expect.arrayContaining([ expect.stringMatching(/^a\.js .+ms$/), - expect.stringMatching(/^b\.js .+ms$/), + expect.stringMatching(/^b\.js .+ms \(unchanged\)$/), ]), ); @@ -146,8 +146,8 @@ describe("--cache option", () => { ]); expect(secondStdout.split("\n")).toEqual( expect.arrayContaining([ - expect.stringMatching(/^a\.js .+ms \(cached\)$/), - expect.stringMatching(/^b\.js .+ms \(cached\)$/), + expect.stringMatching(/^a\.js .+ms \(unchanged\) \(cached\)$/), + expect.stringMatching(/^b\.js .+ms \(unchanged\) \(cached\)$/), ]), ); }); @@ -167,7 +167,7 @@ describe("--cache option", () => { expect(firstStdout.split("\n")).toEqual( expect.arrayContaining([ expect.stringMatching(/^a\.js .+ms$/), - expect.stringMatching(/^b\.js .+ms$/), + expect.stringMatching(/^b\.js .+ms \(unchanged\)$/), ]), ); @@ -182,7 +182,7 @@ describe("--cache option", () => { // the cache of `b.js` is only available. expect.arrayContaining([ expect.stringMatching(/^a\.js .+ms$/), - expect.stringMatching(/^b\.js .+ms \(cached\)$/), + expect.stringMatching(/^b\.js .+ms \(unchanged\) \(cached\)$/), ]), ); }); @@ -202,7 +202,7 @@ describe("--cache option", () => { expect(firstStdout.split("\n")).toEqual( expect.arrayContaining([ expect.stringMatching(/^a\.js .+ms$/), - expect.stringMatching(/^b\.js .+ms$/), + expect.stringMatching(/^b\.js .+ms \(unchanged\)$/), ]), ); @@ -218,7 +218,7 @@ describe("--cache option", () => { // the cache of `b.js` is only available. expect.arrayContaining([ expect.stringMatching(/^a\.js .+ms$/), - expect.stringMatching(/^b\.js .+ms \(cached\)$/), + expect.stringMatching(/^b\.js .+ms \(unchanged\) \(cached\)$/), ]), ); }); @@ -234,7 +234,7 @@ describe("--cache option", () => { expect(firstStdout.split("\n")).toEqual( expect.arrayContaining([ expect.stringMatching(/^a\.js .+ms$/), - expect.stringMatching(/^b\.js .+ms$/), + expect.stringMatching(/^b\.js .+ms \(unchanged\)$/), ]), ); @@ -250,7 +250,7 @@ describe("--cache option", () => { expect(secondStdout.split("\n")).toEqual( expect.arrayContaining([ expect.stringMatching(/^a\.js .+ms$/), - expect.stringMatching(/^b\.js .+ms$/), + expect.stringMatching(/^b\.js .+ms \(unchanged\)$/), ]), ); }); @@ -273,7 +273,7 @@ describe("--cache option", () => { expect(secondStdout.split("\n")).toEqual( expect.arrayContaining([ expect.stringMatching(/^a\.js .+ms$/), - expect.stringMatching(/^b\.js .+ms \(cached\)$/), + expect.stringMatching(/^b\.js .+ms \(unchanged\) \(cached\)$/), ]), ); }); @@ -309,7 +309,7 @@ describe("--cache option", () => { expect(thirdStdout.split("\n")).toEqual( expect.arrayContaining([ expect.stringMatching(/^a\.js .+ms$/), - expect.stringMatching(/^b\.js .+ms \(cached\)$/), + expect.stringMatching(/^b\.js .+ms \(unchanged\) \(cached\)$/), ]), ); }); @@ -336,7 +336,7 @@ describe("--cache option", () => { expect(firstStdout.split("\n")).toEqual( expect.arrayContaining([ expect.stringMatching(/^a\.js .+ms$/), - expect.stringMatching(/^b\.js .+ms$/), + expect.stringMatching(/^b\.js .+ms \(unchanged\)$/), ]), ); @@ -394,7 +394,7 @@ describe("--cache option", () => { expect(firstStdout.split("\n")).toEqual( expect.arrayContaining([ expect.stringMatching(/^a\.js .+ms$/), - expect.stringMatching(/^b\.js .+ms$/), + expect.stringMatching(/^b\.js .+ms \(unchanged\)$/), ]), ); @@ -404,8 +404,8 @@ describe("--cache option", () => { ); expect(secondStdout.split("\n")).toEqual( expect.arrayContaining([ - expect.stringMatching(/^a\.js .+ms \(cached\)$/), - expect.stringMatching(/^b\.js .+ms \(cached\)$/), + expect.stringMatching(/^a\.js .+ms \(unchanged\) \(cached\)$/), + expect.stringMatching(/^b\.js .+ms \(unchanged\) \(cached\)$/), ]), ); }); @@ -425,7 +425,7 @@ describe("--cache option", () => { expect(firstStdout.split("\n")).toEqual( expect.arrayContaining([ expect.stringMatching(/^a\.js .+ms$/), - expect.stringMatching(/^b\.js .+ms$/), + expect.stringMatching(/^b\.js .+ms \(unchanged\)$/), ]), ); @@ -440,7 +440,7 @@ describe("--cache option", () => { // the cache of `b.js` is only available. expect.arrayContaining([ expect.stringMatching(/^a\.js .+ms$/), - expect.stringMatching(/^b\.js .+ms \(cached\)$/), + expect.stringMatching(/^b\.js .+ms \(unchanged\) \(cached\)$/), ]), ); }); @@ -460,7 +460,7 @@ describe("--cache option", () => { expect(firstStdout.split("\n")).toEqual( expect.arrayContaining([ expect.stringMatching(/^a\.js .+ms$/), - expect.stringMatching(/^b\.js .+ms$/), + expect.stringMatching(/^b\.js .+ms \(unchanged\)$/), ]), ); @@ -474,8 +474,8 @@ describe("--cache option", () => { ); expect(secondStdout.split("\n")).toEqual( expect.arrayContaining([ - expect.stringMatching(/^a\.js .+ms \(cached\)$/), - expect.stringMatching(/^b\.js .+ms \(cached\)$/), + expect.stringMatching(/^a\.js .+ms \(unchanged\) \(cached\)$/), + expect.stringMatching(/^b\.js .+ms \(unchanged\) \(cached\)$/), ]), ); }); @@ -491,7 +491,7 @@ describe("--cache option", () => { expect(firstStdout.split("\n")).toEqual( expect.arrayContaining([ expect.stringMatching(/^a\.js .+ms$/), - expect.stringMatching(/^b\.js .+ms$/), + expect.stringMatching(/^b\.js .+ms \(unchanged\)$/), ]), ); @@ -507,7 +507,7 @@ describe("--cache option", () => { expect(secondStdout.split("\n")).toEqual( expect.arrayContaining([ expect.stringMatching(/^a\.js .+ms$/), - expect.stringMatching(/^b\.js .+ms$/), + expect.stringMatching(/^b\.js .+ms \(unchanged\)$/), ]), ); }); @@ -530,7 +530,7 @@ describe("--cache option", () => { expect(secondStdout.split("\n")).toEqual( expect.arrayContaining([ expect.stringMatching(/^a\.js .+ms$/), - expect.stringMatching(/^b\.js .+ms \(cached\)$/), + expect.stringMatching(/^b\.js .+ms \(unchanged\) \(cached\)$/), ]), ); }); @@ -566,7 +566,7 @@ describe("--cache option", () => { expect(thirdStdout.split("\n")).toEqual( expect.arrayContaining([ expect.stringMatching(/^a\.js .+ms$/), - expect.stringMatching(/^b\.js .+ms \(cached\)$/), + expect.stringMatching(/^b\.js .+ms \(unchanged\) \(cached\)$/), ]), ); }); @@ -593,7 +593,7 @@ describe("--cache option", () => { expect(firstStdout.split("\n")).toEqual( expect.arrayContaining([ expect.stringMatching(/^a\.js .+ms$/), - expect.stringMatching(/^b\.js .+ms$/), + expect.stringMatching(/^b\.js .+ms \(unchanged\)$/), ]), ); @@ -677,7 +677,7 @@ describe("--cache option", () => { expect(firstStdout.split("\n")).toEqual( expect.arrayContaining([ expect.stringMatching(/^a\.js .+ms$/), - expect.stringMatching(/^b\.js .+ms$/), + expect.stringMatching(/^b\.js .+ms \(unchanged\)$/), ]), ); @@ -687,8 +687,8 @@ describe("--cache option", () => { ); expect(secondStdout.split("\n")).toEqual( expect.arrayContaining([ - expect.stringMatching(/^a\.js .+ms \(cached\)$/), - expect.stringMatching(/^b\.js .+ms \(cached\)$/), + expect.stringMatching(/^a\.js .+ms \(unchanged\) \(cached\)$/), + expect.stringMatching(/^b\.js .+ms \(unchanged\) \(cached\)$/), ]), ); });