Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions test/__fixtures__/syntax-errors/invalid-1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
foo (+-) bar
1 change: 1 addition & 0 deletions test/__fixtures__/syntax-errors/invalid-2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
foo (+-) bar
Empty file.
1 change: 1 addition & 0 deletions test/__fixtures__/syntax-errors/valid-1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
function foo() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Line breaking after filepath with errors (stderr) 1`] = `
"[error] invalid-1.js: SyntaxError: Unexpected token (1:8)
[error] > 1 | foo (+-) bar
[error] | ^
[error] 2 |
[error] invalid-2.js: SyntaxError: Unexpected token (1:8)
[error] > 1 | foo (+-) bar
[error] | ^
[error] 2 |
[error] invalid-2.unknown: UndefinedParserError: No parser could be inferred for file "$CWD/invalid-2.unknown"."
`;

exports[`Line breaking after filepath with errors (stderr) 2`] = `
"invalid-1.js
invalid-2.js
invalid-2.unknown"
`;

exports[`Line breaking after filepath with errors (stderr) 3`] = `
"[error] invalid-1.js: SyntaxError: Unexpected token (1:8)
[error] > 1 | foo (+-) bar
[error] | ^
[error] 2 |
[error] invalid-2.js: SyntaxError: Unexpected token (1:8)
[error] > 1 | foo (+-) bar
[error] | ^
[error] 2 |
[error] invalid-2.unknown: UndefinedParserError: No parser could be inferred for file "$CWD/invalid-2.unknown"."
`;

exports[`Line breaking after filepath with errors (stderr) 4`] = `
"[error] invalid-1.js: SyntaxError: Unexpected token (1:8)
[error] > 1 | foo (+-) bar
[error] | ^
[error] 2 |
[error] invalid-2.js: SyntaxError: Unexpected token (1:8)
[error] > 1 | foo (+-) bar
[error] | ^
[error] 2 |
[error] invalid-2.unknown: UndefinedParserError: No parser could be inferred for file "$CWD/invalid-2.unknown"."
`;

exports[`Line breaking after filepath with errors (stdout) 1`] = `"function foo() {}"`;

exports[`Line breaking after filepath with errors (stdout) 2`] = `""`;

exports[`Line breaking after filepath with errors (stdout) 3`] = `"Checking formatting..."`;

exports[`Line breaking after filepath with errors (stdout) 4`] = `""`;

exports[`Line breaking after filepath with errors (write) 1`] = `[]`;

exports[`Line breaking after filepath with errors (write) 2`] = `[]`;

exports[`Line breaking after filepath with errors (write) 3`] = `[]`;

exports[`Line breaking after filepath with errors (write) 4`] = `[]`;
19 changes: 19 additions & 0 deletions test/__tests__/line-after-filepath-with-errors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { runCli } from "../utils";

describe("Line breaking after filepath with errors", () => {
runCli("syntax-errors", ["./*.{js,unknown}"]).test({
status: 1,
});
// TODO (43081j): this test throws errors in prettier. here it doesn't, and
// lists each invalid file path in the output (stderr). we should decide
// if to align with prettier
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see this TODO and the one above

this has been raised in another PR too. basically this block:

prettier-cli/src/index.ts

Lines 181 to 185 in 5d5a6ca

if (options.check || options.write) {
stderr.prefixed.error(`${fileRelativePath}: ${error}`);
} else if (options.list) {
stderr.error(fileRelativePath);
}

means that with no args, errors are not raised and are ignored

this means running with list: true or check: true behaves differently than with no args (i.e. both false)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should first add the fourth mode of operation as mentioned in #30, then I need to look at what the difference is exactly, because if prettier just throws it seems better to output a comprehensible error, while still erroring, no?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "forth mode", "dump" is implemented now, maybe we can reference that here if needed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the two tests fail in prettier because the files matching the glob are invalid I think (syntax errors)

so in this test (--list-different) and the argless one, we do error in prettier but not in prettier CLI

the fourth mode doesn't seem relevant now that I think about it. in general if a glob matches invalid files, it seems we skip them? but I don't remember what past-james was doing here, so I'm just going off the TODOs

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if aligning with the old CLI in this aspect isn't a huge pain in the ass we should just do that 🤔 That seems the only blocker for this PR, right?

runCli("syntax-errors", ["--list-different", "./*.{js,unknown}"]).test({
status: 1,
});
runCli("syntax-errors", ["--check", "./*.{js,unknown}"]).test({
status: 1,
});
runCli("syntax-errors", ["--write", "./*.{js,unknown}"]).test({
status: 1,
});
});