From b8af46e0075f659f4e373e249b0f19b3cb0f62a9 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Sun, 31 Mar 2024 16:39:40 -0400 Subject: fix(check): ignore certain diagnostics in remote modules and when publishing (#23119) Unused locals and parameters don't make sense to surface in remote modules. Additionally, fast check can cause these kind of diagnostics when publishing, so they should be ignored. Closes #22959 --- cli/tools/check.rs | 43 +++++++++++++++++++++---------------------- cli/tools/registry/mod.rs | 4 ++++ 2 files changed, 25 insertions(+), 22 deletions(-) (limited to 'cli/tools') diff --git a/cli/tools/check.rs b/cli/tools/check.rs index ec4490017..87ec88a4a 100644 --- a/cli/tools/check.rs +++ b/cli/tools/check.rs @@ -200,28 +200,13 @@ impl TypeChecker { check_mode: type_check_mode, })?; - let mut diagnostics = if type_check_mode == TypeCheckMode::Local { - response.diagnostics.filter(|d| { - if let Some(file_name) = &d.file_name { - if !file_name.starts_with("http") { - if ModuleSpecifier::parse(file_name) - .map(|specifier| !self.node_resolver.in_npm_package(&specifier)) - .unwrap_or(true) - { - Some(d.clone()) - } else { - None - } - } else { - None - } - } else { - Some(d.clone()) - } - }) - } else { - response.diagnostics - }; + let mut diagnostics = response.diagnostics.filter(|d| { + if self.is_remote_diagnostic(d) { + type_check_mode == TypeCheckMode::All && d.include_when_remote() + } else { + true + } + }); diagnostics.apply_fast_check_source_maps(&graph); @@ -239,6 +224,20 @@ impl TypeChecker { Ok((graph, diagnostics)) } + + fn is_remote_diagnostic(&self, d: &tsc::Diagnostic) -> bool { + let Some(file_name) = &d.file_name else { + return false; + }; + if file_name.starts_with("https://") || file_name.starts_with("http://") { + return true; + } + // check if in an npm package + let Ok(specifier) = ModuleSpecifier::parse(file_name) else { + return false; + }; + self.node_resolver.in_npm_package(&specifier) + } } enum CheckHashResult { diff --git a/cli/tools/registry/mod.rs b/cli/tools/registry/mod.rs index b40aeaeb4..3d13a52b7 100644 --- a/cli/tools/registry/mod.rs +++ b/cli/tools/registry/mod.rs @@ -924,6 +924,10 @@ async fn build_and_check_graph_for_publish( }, ) .await?; + // ignore unused parameter diagnostics that may occur due to fast check + // not having function body implementations + let check_diagnostics = + check_diagnostics.filter(|d| d.include_when_remote()); if !check_diagnostics.is_empty() { bail!( concat!( -- cgit v1.2.3