Skip to content

Commit

Permalink
fix(fmt): should fail --check on parse error (#14907)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret committed Jun 18, 2022
1 parent fa7cad0 commit f564497
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cli/tests/integration/fmt_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,12 @@ itest!(fmt_check_ignore {
exit_code: 0,
});

itest!(fmt_check_parse_error {
args: "fmt --check fmt/parse_error/parse_error.ts",
output: "fmt/fmt_check_parse_error.out",
exit_code: 1,
});

itest!(fmt_stdin {
args: "fmt -",
input: Some("const a = 1\n"),
Expand Down
6 changes: 6 additions & 0 deletions cli/tests/testdata/fmt/fmt_check_parse_error.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Error checking: [WILDCARD]
Line 2, column 7: Expected '{', got '<eof>'

class Test
~~~~
error: Found 1 not formatted file in 1 file
2 changes: 2 additions & 0 deletions cli/tests/testdata/fmt/parse_error/parse_error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// a file that purposefully will cause an error
class Test
1 change: 1 addition & 0 deletions cli/tools/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ async fn check_source_files(
incremental_cache.update_file(&file_path, &file_text);
}
Err(e) => {
not_formatted_files_count.fetch_add(1, Ordering::Relaxed);
let _g = output_lock.lock();
eprintln!("Error checking: {}", file_path.to_string_lossy());
eprintln!(" {}", e);
Expand Down
1 change: 1 addition & 0 deletions tools/lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ async function dlint() {
":!:cli/dts/**",
":!:cli/tests/testdata/encoding/**",
":!:cli/tests/testdata/error_syntax.js",
":!:cli/tests/testdata/fmt/**",
":!:cli/tests/testdata/lint/**",
":!:cli/tests/testdata/tsc/**",
":!:cli/tsc/*typescript.js",
Expand Down

0 comments on commit f564497

Please sign in to comment.