mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 15:04:11 -05:00
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
This commit is contained in:
parent
0144594044
commit
b8af46e007
8 changed files with 73 additions and 25 deletions
|
@ -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 {
|
||||
|
|
|
@ -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!(
|
||||
|
|
|
@ -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<P>(&self, predicate: P) -> Self
|
||||
pub fn filter<P>(self, predicate: P) -> Self
|
||||
where
|
||||
P: FnMut(&Diagnostic) -> Option<Diagnostic>,
|
||||
P: FnMut(&Diagnostic) -> bool,
|
||||
{
|
||||
let diagnostics = self.0.iter().filter_map(predicate).collect();
|
||||
let diagnostics = self.0.into_iter().filter(predicate).collect();
|
||||
Self(diagnostics)
|
||||
}
|
||||
|
||||
|
|
10
tests/specs/jsr/no_unused_params/__test__.jsonc
Normal file
10
tests/specs/jsr/no_unused_params/__test__.jsonc
Normal file
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"base": "jsr",
|
||||
"steps": [{
|
||||
"args": "check --all main.ts",
|
||||
"output": "main.out"
|
||||
}, {
|
||||
"args": "publish --dry-run",
|
||||
"output": "publish.out"
|
||||
}]
|
||||
}
|
9
tests/specs/jsr/no_unused_params/deno.json
Normal file
9
tests/specs/jsr/no_unused_params/deno.json
Normal file
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"name": "@scope/package",
|
||||
"version": "0.0.0",
|
||||
"exports": "./main.ts",
|
||||
"lock": false,
|
||||
"compilerOptions": {
|
||||
"noUnusedParameters": true
|
||||
}
|
||||
}
|
4
tests/specs/jsr/no_unused_params/main.out
Normal file
4
tests/specs/jsr/no_unused_params/main.out
Normal file
|
@ -0,0 +1,4 @@
|
|||
Download http://127.0.0.1:4250/@denotest/add/meta.json
|
||||
Download http://127.0.0.1:4250/@denotest/add/1.0.0_meta.json
|
||||
Download http://127.0.0.1:4250/@denotest/add/1.0.0/mod.ts
|
||||
Check file:///[WILDLINE]/no_unused_params/main.ts
|
5
tests/specs/jsr/no_unused_params/main.ts
Normal file
5
tests/specs/jsr/no_unused_params/main.ts
Normal file
|
@ -0,0 +1,5 @@
|
|||
import * as inner from "jsr:@denotest/add";
|
||||
|
||||
export function add(a: number, b: number): number {
|
||||
return inner.add(a, b);
|
||||
}
|
10
tests/specs/jsr/no_unused_params/publish.out
Normal file
10
tests/specs/jsr/no_unused_params/publish.out
Normal file
|
@ -0,0 +1,10 @@
|
|||
Check file:///[WILDLINE]/main.ts
|
||||
Checking for slow types in the public API...
|
||||
Check file:///[WILDLINE]/main.ts
|
||||
Simulating publish of @scope/package@0.0.0 with files:
|
||||
file:///[WILDLINE]/__test__.jsonc ([WILDLINE])
|
||||
file:///[WILDLINE]/deno.json ([WILDLINE])
|
||||
file:///[WILDLINE]/main.out ([WILDLINE])
|
||||
file:///[WILDLINE]/main.ts ([WILDLINE])
|
||||
file:///[WILDLINE]/publish.out ([WILDLINE])
|
||||
Warning Aborting due to --dry-run
|
Loading…
Reference in a new issue