Clear filename before print ignored file code to screen (#14794)
This commit is contained in:
1 parent
abc7440c3e
commit
c0f6f2da8b
10 files changed
+88
-12
No files matched your search
@@ -0,0 +1,15 @@
|
||||
#### Clear filename before print ignored file code to screen (#14794 by @fisker)
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```sh
|
||||
# Input
|
||||
echo test.js > .prettierignore
|
||||
echo code > test.js
|
||||
prettier ./test.js
|
||||
|
||||
# Prettier stable
|
||||
test.jscode
|
||||
|
||||
# Prettier main
|
||||
code
|
||||
```
|
||||
+3
-4
@@ -370,6 +370,7 @@ async function formatFiles(context) {
|
||||
}
|
||||
|
||||
if (isFileIgnored) {
|
||||
printedFilename?.clear();
|
||||
writeOutput(context, { formatted: input }, options);
|
||||
continue;
|
||||
}
|
||||
@@ -399,10 +400,8 @@ async function formatFiles(context) {
|
||||
const isDifferent = output !== input;
|
||||
let shouldSetCache = !isDifferent;
|
||||
|
||||
if (printedFilename) {
|
||||
// Remove previously printed filename to log it with duration.
|
||||
printedFilename.clear();
|
||||
}
|
||||
// Remove previously printed filename to log it with duration.
|
||||
printedFilename?.clear();
|
||||
|
||||
if (performanceTestFlag) {
|
||||
context.logger.log(
|
||||
|
||||
@@ -52,14 +52,18 @@ exports[`Line breaking after filepath with errors (stdout) 1`] = `
|
||||
"invalid-1.js
|
||||
invalid-2.js
|
||||
invalid-2.unknown
|
||||
valid-1.jsfunction foo() {}"
|
||||
valid-1.js
|
||||
[[called readline.clearLine(process.stdout)]]
|
||||
function foo() {}"
|
||||
`;
|
||||
|
||||
exports[`Line breaking after filepath with errors (stdout) 2`] = `
|
||||
"invalid-1.js
|
||||
invalid-2.js
|
||||
invalid-2.unknown
|
||||
valid-1.js"
|
||||
valid-1.js
|
||||
[[called readline.clearLine(process.stdout)]]
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`Line breaking after filepath with errors (stdout) 3`] = `
|
||||
@@ -67,13 +71,19 @@ exports[`Line breaking after filepath with errors (stdout) 3`] = `
|
||||
invalid-1.js
|
||||
invalid-2.js
|
||||
invalid-2.unknown
|
||||
valid-1.jsAll matched files use Prettier code style!"
|
||||
valid-1.js
|
||||
[[called readline.clearLine(process.stdout)]]
|
||||
All matched files use Prettier code style!"
|
||||
`;
|
||||
|
||||
exports[`Line breaking after filepath with errors (stdout) 4`] = `
|
||||
"invalid-1.js
|
||||
invalid-2.js
|
||||
invalid-2.unknownvalid-1.jsvalid-1.js 0ms"
|
||||
invalid-2.unknown
|
||||
[[called readline.clearLine(process.stdout)]]
|
||||
valid-1.js
|
||||
[[called readline.clearLine(process.stdout)]]
|
||||
valid-1.js 0ms"
|
||||
`;
|
||||
|
||||
exports[`Line breaking after filepath with errors (write) 1`] = `[]`;
|
||||
|
||||
@@ -6,7 +6,9 @@ exports[`no file diffs with --check + formatted file (stderr) 2`] = `""`;
|
||||
|
||||
exports[`no file diffs with --check + formatted file (stdout) 1`] = `
|
||||
"Checking formatting...
|
||||
formatted.jsAll matched files use Prettier code style!"
|
||||
formatted.js
|
||||
[[called readline.clearLine(process.stdout)]]
|
||||
All matched files use Prettier code style!"
|
||||
`;
|
||||
|
||||
exports[`no file diffs with --check + formatted file (stdout) 2`] = `
|
||||
@@ -22,7 +24,11 @@ exports[`no file diffs with --list-different + formatted file (stderr) 1`] = `""
|
||||
|
||||
exports[`no file diffs with --list-different + formatted file (stderr) 2`] = `""`;
|
||||
|
||||
exports[`no file diffs with --list-different + formatted file (stdout) 1`] = `"formatted.js"`;
|
||||
exports[`no file diffs with --list-different + formatted file (stdout) 1`] = `
|
||||
"formatted.js
|
||||
[[called readline.clearLine(process.stdout)]]
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`no file diffs with --list-different + formatted file (stdout) 2`] = `""`;
|
||||
|
||||
@@ -42,7 +48,9 @@ exports[`output with --check + unformatted differs when piped (stderr) 2`] = `
|
||||
|
||||
exports[`output with --check + unformatted differs when piped (stdout) 1`] = `
|
||||
"Checking formatting...
|
||||
unformatted.js"
|
||||
unformatted.js
|
||||
[[called readline.clearLine(process.stdout)]]
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`output with --check + unformatted differs when piped (stdout) 2`] = `"Checking formatting..."`;
|
||||
@@ -71,7 +79,11 @@ exports[`output with --list-different + unformatted differs when piped (stderr)
|
||||
|
||||
exports[`output with --list-different + unformatted differs when piped (stderr) 2`] = `""`;
|
||||
|
||||
exports[`output with --list-different + unformatted differs when piped (stdout) 1`] = `"unformatted.jsunformatted.js"`;
|
||||
exports[`output with --list-different + unformatted differs when piped (stdout) 1`] = `
|
||||
"unformatted.js
|
||||
[[called readline.clearLine(process.stdout)]]
|
||||
unformatted.js"
|
||||
`;
|
||||
|
||||
exports[`output with --list-different + unformatted differs when piped (stdout) 2`] = `"unformatted.js"`;
|
||||
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`Line breaking after filepath with errors (stdout) 1`] = `
|
||||
"ignored.js
|
||||
[[called readline.clearLine(process.stdout)]]
|
||||
foo(
|
||||
)"
|
||||
`;
|
||||
|
||||
exports[`Line breaking after filepath with errors (stdout) 2`] = `
|
||||
"not-ignored.js
|
||||
[[called readline.clearLine(process.stdout)]]
|
||||
foo();"
|
||||
`;
|
||||
@@ -0,0 +1,8 @@
|
||||
describe("Line breaking after filepath with errors", () => {
|
||||
runCli("cli/print-code", ["./ignored.js"], {
|
||||
stdoutIsTTY: true,
|
||||
}).test({ status: 0, write: [], stderr: "" });
|
||||
runCli("cli/print-code", ["./not-ignored.js"], {
|
||||
stdoutIsTTY: true,
|
||||
}).test({ status: 0, write: [], stderr: "" });
|
||||
});
|
||||
@@ -2,6 +2,7 @@ import { workerData, parentPort } from "node:worker_threads";
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import url from "node:url";
|
||||
import readline from "node:readline";
|
||||
import { cosmiconfig } from "cosmiconfig";
|
||||
import { prettierCli, mockable as mockableModuleFile } from "./env.js";
|
||||
|
||||
@@ -40,6 +41,18 @@ async function run() {
|
||||
: filename
|
||||
);
|
||||
|
||||
readline.clearLine = (stream) => {
|
||||
stream.write(
|
||||
`\n[[called readline.clearLine(${
|
||||
stream === process.stdout
|
||||
? "process.stdout"
|
||||
: stream === process.stderr
|
||||
? "process.stderr"
|
||||
: "unknown stream"
|
||||
})]]\n`
|
||||
);
|
||||
};
|
||||
|
||||
process.stdin.isTTY = Boolean(options.isTTY);
|
||||
process.stdout.isTTY = Boolean(options.stdoutIsTTY);
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
ignored.js
|
||||
@@ -0,0 +1,2 @@
|
||||
foo(
|
||||
)
|
||||
@@ -0,0 +1,2 @@
|
||||
foo(
|
||||
)
|
||||
Reference in new issue
Block a user