summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2022-06-18 12:44:43 -0400
committerGitHub <noreply@github.com>2022-06-18 12:44:43 -0400
commitf564497630d8d12023cd093904bf237ab1079a94 (patch)
tree1c14d4e641e739fdf99cf4a16d45db35c1da515f
parentfa7cad06de648a7e35995b9a366ae2cee3b3bc4f (diff)
fix(fmt): should fail `--check` on parse error (#14907)
-rw-r--r--cli/tests/integration/fmt_tests.rs6
-rw-r--r--cli/tests/testdata/fmt/fmt_check_parse_error.out6
-rw-r--r--cli/tests/testdata/fmt/parse_error/parse_error.ts2
-rw-r--r--cli/tools/fmt.rs1
-rwxr-xr-xtools/lint.js1
5 files changed, 16 insertions, 0 deletions
diff --git a/cli/tests/integration/fmt_tests.rs b/cli/tests/integration/fmt_tests.rs
index 18ad2ab29..3f4bc15cb 100644
--- a/cli/tests/integration/fmt_tests.rs
+++ b/cli/tests/integration/fmt_tests.rs
@@ -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"),
diff --git a/cli/tests/testdata/fmt/fmt_check_parse_error.out b/cli/tests/testdata/fmt/fmt_check_parse_error.out
new file mode 100644
index 000000000..d9b918af7
--- /dev/null
+++ b/cli/tests/testdata/fmt/fmt_check_parse_error.out
@@ -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
diff --git a/cli/tests/testdata/fmt/parse_error/parse_error.ts b/cli/tests/testdata/fmt/parse_error/parse_error.ts
new file mode 100644
index 000000000..136d16508
--- /dev/null
+++ b/cli/tests/testdata/fmt/parse_error/parse_error.ts
@@ -0,0 +1,2 @@
+// a file that purposefully will cause an error
+class Test
diff --git a/cli/tools/fmt.rs b/cli/tools/fmt.rs
index 3eb620900..4e399bcf5 100644
--- a/cli/tools/fmt.rs
+++ b/cli/tools/fmt.rs
@@ -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);
diff --git a/tools/lint.js b/tools/lint.js
index 7a77c09ae..18be09c65 100755
--- a/tools/lint.js
+++ b/tools/lint.js
@@ -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",