diff --git a/cli/tools/check.rs b/cli/tools/check.rs index ec44900177..87ec88a4ae 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 b40aeaeb4b..3d13a52b77 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!( diff --git a/cli/tsc/diagnostics.rs b/cli/tsc/diagnostics.rs index 362385c07a..9525d1855d 100644 --- a/cli/tsc/diagnostics.rs +++ b/cli/tsc/diagnostics.rs @@ -136,6 +136,13 @@ pub struct Diagnostic { } impl Diagnostic { + /// If this diagnostic should be included when it comes from a remote module. + pub fn include_when_remote(&self) -> bool { + /// TS6133: value is declared but its value is never read (noUnusedParameters and noUnusedLocals) + const TS6133: u64 = 6133; + self.code != TS6133 + } + fn fmt_category_and_code(&self, f: &mut fmt::Formatter) -> fmt::Result { let category = match self.category { DiagnosticCategory::Error => "ERROR", @@ -275,11 +282,11 @@ impl Diagnostics { /// Return a set of diagnostics where only the values where the predicate /// returns `true` are included. - pub fn filter
(&self, predicate: P) -> Self + pub fn filter
(self, predicate: P) -> Self
where
- P: FnMut(&Diagnostic) -> Option