From f0df54fc70ec1781a3ffec232fefc38cabf39c37 Mon Sep 17 00:00:00 2001 From: HasanAlrimawi <141642411+HasanAlrimawi@users.noreply.github.com> Date: Wed, 24 Jul 2024 00:17:17 +0300 Subject: [PATCH] fix: enable the reporting of parsing related problems when running deno lint (#24332) --- .dprint.json | 1 + cli/tools/lint/mod.rs | 7 ++++++- .../lint/syntax_error_reporting/__test__.jsonc | 5 +++++ tests/specs/lint/syntax_error_reporting/lint.out | 16 ++++++++++++++++ .../specs/lint/syntax_error_reporting/script.ts | 1 + 5 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 tests/specs/lint/syntax_error_reporting/__test__.jsonc create mode 100644 tests/specs/lint/syntax_error_reporting/lint.out create mode 100644 tests/specs/lint/syntax_error_reporting/script.ts diff --git a/.dprint.json b/.dprint.json index 1ab5dfaaea..beebc4d874 100644 --- a/.dprint.json +++ b/.dprint.json @@ -41,6 +41,7 @@ "tests/registry/", "tests/specs/fmt", "tests/specs/lint/bom", + "tests/specs/lint/syntax_error_reporting", "tests/specs/publish/no_check_surfaces_syntax_error", "tests/testdata/byte_order_mark.ts", "tests/testdata/encoding", diff --git a/cli/tools/lint/mod.rs b/cli/tools/lint/mod.rs index 05458a7b0d..3b2af12fba 100644 --- a/cli/tools/lint/mod.rs +++ b/cli/tools/lint/mod.rs @@ -646,7 +646,12 @@ fn handle_lint_result( let mut reporter = reporter_lock.lock(); match result { - Ok((_source, mut file_diagnostics)) => { + Ok((source, mut file_diagnostics)) => { + if !source.diagnostics().is_empty() { + for parse_diagnostic in source.diagnostics() { + log::warn!("{}: {}", colors::yellow("warn"), parse_diagnostic); + } + } file_diagnostics.sort_by(|a, b| match a.specifier.cmp(&b.specifier) { std::cmp::Ordering::Equal => a.range.start.cmp(&b.range.start), file_order => file_order, diff --git a/tests/specs/lint/syntax_error_reporting/__test__.jsonc b/tests/specs/lint/syntax_error_reporting/__test__.jsonc new file mode 100644 index 0000000000..532caf3208 --- /dev/null +++ b/tests/specs/lint/syntax_error_reporting/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "lint script.ts", + "output": "lint.out", + "exitCode": 1 +} diff --git a/tests/specs/lint/syntax_error_reporting/lint.out b/tests/specs/lint/syntax_error_reporting/lint.out new file mode 100644 index 0000000000..31e4c576b6 --- /dev/null +++ b/tests/specs/lint/syntax_error_reporting/lint.out @@ -0,0 +1,16 @@ +warn: Unterminated string constant at [WILDCARD]script.ts:1:13 + + const foo = 'bar + ~~~~ +error[no-unused-vars]: `foo` is never used + --> [WILDCARD]script.ts:1:7 + | +1 | const foo = 'bar + | ^^^ + = hint: If this is intentional, prefix it with an underscore like `_foo` + + docs: https://lint.deno.land/rules/no-unused-vars + + +Found 1 problem +Checked 1 file diff --git a/tests/specs/lint/syntax_error_reporting/script.ts b/tests/specs/lint/syntax_error_reporting/script.ts new file mode 100644 index 0000000000..4458a11ae6 --- /dev/null +++ b/tests/specs/lint/syntax_error_reporting/script.ts @@ -0,0 +1 @@ +const foo = 'bar