From 2a2da281df718f24cbb6f3fda71ae68fd890bd2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Thu, 14 Nov 2024 14:41:00 +0100 Subject: [PATCH] wire up diagnostic --- cli/tools/lint/linter.rs | 20 ++++++++++++++++---- cli/tools/lint/mod.rs | 13 +++++++------ 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/cli/tools/lint/linter.rs b/cli/tools/lint/linter.rs index b0981b0d57..27f5e042a2 100644 --- a/cli/tools/lint/linter.rs +++ b/cli/tools/lint/linter.rs @@ -7,11 +7,11 @@ use deno_ast::MediaType; use deno_ast::ModuleSpecifier; use deno_ast::ParsedSource; use deno_ast::SourceTextInfo; -use deno_core::anyhow::bail; use deno_core::anyhow::Context; use deno_core::error::AnyError; use deno_graph::ModuleGraph; use deno_lint::diagnostic::LintDiagnostic; +use deno_lint::diagnostic::LintDiagnosticDetails; use deno_lint::linter::LintConfig as DenoLintConfig; use deno_lint::linter::LintFileOptions; use deno_lint::linter::Linter as DenoLintLinter; @@ -33,8 +33,7 @@ pub enum LintResult { }, /// File was not parsed and linted because, eg. it might have /// been a minified file. - #[allow(unused)] - Skipped, + Skipped { diagnostic: LintDiagnostic }, } pub struct CliLinterOptions { @@ -114,7 +113,20 @@ impl CliLinter { let metrics = minified_file::analyze_content(&source_code); if metrics.is_likely_minified() { - Ok(LintResult::Skipped); + let details = LintDiagnosticDetails { + message: "File was not linted, because it's minified".to_string(), + code: "".to_string(), + hint: None, + fixes: vec![], + custom_docs_url: None, + info: vec![], + }; + let diagnostic = LintDiagnostic { + specifier, + range: None, + details, + }; + return Ok(LintResult::Skipped { diagnostic }); } let media_type = if let Some(ext) = ext { diff --git a/cli/tools/lint/mod.rs b/cli/tools/lint/mod.rs index 048567834d..f3314815a5 100644 --- a/cli/tools/lint/mod.rs +++ b/cli/tools/lint/mod.rs @@ -524,12 +524,11 @@ fn handle_lint_result( let mut reporter = reporter_lock.lock(); match result { - Ok(lint_result) => { - if let LintResult::Linted { + Ok(lint_result) => match lint_result { + LintResult::Linted { parsed_source, mut diagnostics, - } = lint_result - { + } => { if !parsed_source.diagnostics().is_empty() { for parse_diagnostic in parsed_source.diagnostics() { log::warn!("{}: {}", colors::yellow("warn"), parse_diagnostic); @@ -550,10 +549,12 @@ fn handle_lint_result( reporter.visit_diagnostic(d); } diagnostics.is_empty() - } else { + } + LintResult::Skipped { diagnostic } => { + reporter.visit_diagnostic(&diagnostic); true } - } + }, Err(err) => { reporter.visit_error(file_path, &err); false