Skip to content

Commit 7f0d9c6

Browse files
committed
feat: add dump to error logging
1 parent 50b7054 commit 7f0d9c6

3 files changed

Lines changed: 4 additions & 7 deletions

File tree

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ async function runGlobs(options: Options, pluginsDefaultOptions: PluginsOptions,
182182
const filePath = filesPathsTargets[i];
183183
const fileNameToDisplay = normalizeToPosix(fastRelativePath(rootPath, filePath));
184184
//TODO: Make sure the error is syntax-highlighted when possible
185-
if (options.check || options.write) {
185+
if (options.check || options.write || options.dump) {
186186
stderr.prefixed.error(`${fileNameToDisplay}: ${error}`);
187187
} else if (options.list) {
188188
stderr.error(fileNameToDisplay);

test/__tests__/__snapshots__/infer-parser.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ exports[`stdin with unknown path and no parser --list-different logs error but e
4141

4242
exports[`stdin with unknown path and no parser logs error and exits with 2 (stderr) 1`] = `"[error] UndefinedParserError: No parser could be inferred for file "foo"."`;
4343

44-
exports[`unknown path and no parser multiple files (stderr) 1`] = `""`;
44+
exports[`unknown path and no parser multiple files (stderr) 1`] = `"[error] FOO: UndefinedParserError: No parser could be inferred for file "/tmp/prettier-infer-parser-68670a6cfd1d189a6f3c7fb6c5932306/FOO"."`;
4545

4646
exports[`unknown path and no parser multiple files (stdout) 1`] = `"foo();"`;
4747

test/__tests__/infer-parser.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import { runCli } from "../utils";
22
import { color } from "specialist";
3-
import path from 'node:path';
4-
5-
const FIXTURES_PATH = path.join(process.cwd(), "test", "__fixtures__");
63

74
describe("stdin no path and no parser", () => {
85
describe("logs error and exits with 2", () => {
@@ -108,7 +105,7 @@ describe("--check with unknown path and no parser", () => {
108105
runCli("infer-parser/", ["--check", "*"]).test({
109106
status: 1,
110107
write: [],
111-
stderr: `[${color.red('error')}] FOO: UndefinedParserError: No parser could be inferred for file "${FIXTURES_PATH}/infer-parser/FOO".
108+
stderr: `[${color.red('error')}] FOO: UndefinedParserError: No parser could be inferred for file "__FIXTURES__/FOO".
112109
[${color.yellow('warn')}] foo.js
113110
[${color.yellow('warn')}] Code style issues found in 1 file. Run Prettier with --write to fix.`
114111
});
@@ -145,7 +142,7 @@ describe("--write with unknown path and no parser", () => {
145142
describe("multiple files", () => {
146143
runCli("infer-parser/", ["--write", "*"]).test({
147144
status: 1,
148-
stderr: `[${color.red('error')}] FOO: UndefinedParserError: No parser could be inferred for file "${FIXTURES_PATH}/infer-parser/FOO".`,
145+
stderr: `[${color.red('error')}] FOO: UndefinedParserError: No parser could be inferred for file "__FIXTURES__/FOO".`,
149146
});
150147
});
151148
});

0 commit comments

Comments
 (0)