1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-07 22:58:24 -05:00

wire up diagnostic

This commit is contained in:
Bartek Iwańczuk 2024-11-14 14:41:00 +01:00
parent 4d5f9028fd
commit 2a2da281df
No known key found for this signature in database
GPG key ID: 0C6BCDDC3B3AD750
2 changed files with 23 additions and 10 deletions

View file

@ -7,11 +7,11 @@ use deno_ast::MediaType;
use deno_ast::ModuleSpecifier; use deno_ast::ModuleSpecifier;
use deno_ast::ParsedSource; use deno_ast::ParsedSource;
use deno_ast::SourceTextInfo; use deno_ast::SourceTextInfo;
use deno_core::anyhow::bail;
use deno_core::anyhow::Context; use deno_core::anyhow::Context;
use deno_core::error::AnyError; use deno_core::error::AnyError;
use deno_graph::ModuleGraph; use deno_graph::ModuleGraph;
use deno_lint::diagnostic::LintDiagnostic; use deno_lint::diagnostic::LintDiagnostic;
use deno_lint::diagnostic::LintDiagnosticDetails;
use deno_lint::linter::LintConfig as DenoLintConfig; use deno_lint::linter::LintConfig as DenoLintConfig;
use deno_lint::linter::LintFileOptions; use deno_lint::linter::LintFileOptions;
use deno_lint::linter::Linter as DenoLintLinter; 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 /// File was not parsed and linted because, eg. it might have
/// been a minified file. /// been a minified file.
#[allow(unused)] Skipped { diagnostic: LintDiagnostic },
Skipped,
} }
pub struct CliLinterOptions { pub struct CliLinterOptions {
@ -114,7 +113,20 @@ impl CliLinter {
let metrics = minified_file::analyze_content(&source_code); let metrics = minified_file::analyze_content(&source_code);
if metrics.is_likely_minified() { 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 { let media_type = if let Some(ext) = ext {

View file

@ -524,12 +524,11 @@ fn handle_lint_result(
let mut reporter = reporter_lock.lock(); let mut reporter = reporter_lock.lock();
match result { match result {
Ok(lint_result) => { Ok(lint_result) => match lint_result {
if let LintResult::Linted { LintResult::Linted {
parsed_source, parsed_source,
mut diagnostics, mut diagnostics,
} = lint_result } => {
{
if !parsed_source.diagnostics().is_empty() { if !parsed_source.diagnostics().is_empty() {
for parse_diagnostic in parsed_source.diagnostics() { for parse_diagnostic in parsed_source.diagnostics() {
log::warn!("{}: {}", colors::yellow("warn"), parse_diagnostic); log::warn!("{}: {}", colors::yellow("warn"), parse_diagnostic);
@ -550,10 +549,12 @@ fn handle_lint_result(
reporter.visit_diagnostic(d); reporter.visit_diagnostic(d);
} }
diagnostics.is_empty() diagnostics.is_empty()
} else { }
LintResult::Skipped { diagnostic } => {
reporter.visit_diagnostic(&diagnostic);
true true
} }
} },
Err(err) => { Err(err) => {
reporter.visit_error(file_path, &err); reporter.visit_error(file_path, &err);
false false