Skip to content

Commit e20dc15

Browse files
committed
fix(linter/no-unsafe-declaration-merging): always mark class span as primary
1 parent 7d0b8a1 commit e20dc15

File tree

8 files changed

+44
-32
lines changed

8 files changed

+44
-32
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"plugins": ["eslint", "typescript", "react"],
3+
"categories": {
4+
"correctness": "off"
5+
},
6+
"rules": {
7+
"react/exhaustive-deps": "warn",
8+
"typescript/no-unsafe-declaration-merging": "error"
9+
}
10+
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ function Component() {
1010
}, []);
1111

1212
return null;
13-
}
13+
}
14+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export interface Component<P = {}, S = {}> {}
2+
3+
// oxlint-disable-next-line typescript/no-unsafe-declaration-merging
4+
export abstract class Component<P, S> {}

apps/oxlint/fixtures/exhaustive_deps_disable_directive_issue_13311/.oxlintrc.json

Lines changed: 0 additions & 9 deletions
This file was deleted.

apps/oxlint/src/lint.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,13 +1252,13 @@ mod test {
12521252
}
12531253

12541254
#[test]
1255-
fn test_exhaustive_deps_disable_directive_issue_13311() {
1255+
fn test_disable_directive_issue_13311() {
12561256
// Test that exhaustive-deps diagnostics are reported at the dependency array
12571257
// so that disable directives work correctly
12581258
// Issue: https://github.com/oxc-project/oxc/issues/13311
1259-
let args = &["test.jsx"];
1259+
let args = &["test.jsx", "test2.d.ts"];
12601260
Tester::new()
1261-
.with_cwd("fixtures/exhaustive_deps_disable_directive_issue_13311".into())
1261+
.with_cwd("fixtures/disable_directive_issue_13311".into())
12621262
.test_and_snapshot(args);
12631263
}
12641264

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
source: apps/oxlint/src/tester.rs
3+
---
4+
##########
5+
arguments: test.jsx test2.d.ts
6+
working directory: fixtures/disable_directive_issue_13311
7+
----------
8+
Found 0 warnings and 0 errors.
9+
Finished in <variable>ms on 2 files using 1 threads.
10+
----------
11+
CLI result: LintSucceeded
12+
----------

apps/oxlint/src/snapshots/fixtures__exhaustive_deps_disable_directive_issue_13311_test.jsx@oxlint.snap

Lines changed: 0 additions & 12 deletions
This file was deleted.

crates/oxc_linter/src/rules/typescript/no_unsafe_declaration_merging.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@ use crate::{
1010
rule::Rule,
1111
};
1212

13-
fn no_unsafe_declaration_merging_diagnostic(span: Span, span1: Span) -> OxcDiagnostic {
13+
fn no_unsafe_declaration_merging_diagnostic(
14+
class_span: Span,
15+
interface_span: Span,
16+
) -> OxcDiagnostic {
1417
OxcDiagnostic::warn("Unsafe declaration merging between classes and interfaces.")
1518
.with_help("The TypeScript compiler doesn't check whether properties are initialized, which can lead to TypeScript not detecting code that will cause runtime errors.")
16-
.with_labels([span, span1])
19+
.with_labels([class_span.primary(), interface_span.into()])
1720
}
1821

1922
#[derive(Debug, Default, Clone)]
@@ -65,7 +68,7 @@ impl Rule for NoUnsafeDeclarationMerging {
6568
for symbol_id in ctx.scoping().get_bindings(node.scope_id()).values() {
6669
if let AstKind::Class(scope_class) = get_symbol_kind(*symbol_id, ctx) {
6770
if let Some(scope_class_ident) = scope_class.id.as_ref() {
68-
check_and_diagnostic(&decl.id, scope_class_ident, ctx);
71+
check_and_diagnostic(scope_class_ident, &decl.id, ctx);
6972
}
7073
}
7174
}
@@ -80,12 +83,15 @@ impl Rule for NoUnsafeDeclarationMerging {
8083
}
8184

8285
fn check_and_diagnostic(
83-
ident: &BindingIdentifier,
84-
scope_ident: &BindingIdentifier,
86+
class_binding_ident: &BindingIdentifier,
87+
interface_binding_ident: &BindingIdentifier,
8588
ctx: &LintContext<'_>,
8689
) {
87-
if scope_ident.name.as_str() == ident.name.as_str() {
88-
ctx.diagnostic(no_unsafe_declaration_merging_diagnostic(ident.span, scope_ident.span));
90+
if interface_binding_ident.name.as_str() == class_binding_ident.name.as_str() {
91+
ctx.diagnostic(no_unsafe_declaration_merging_diagnostic(
92+
class_binding_ident.span,
93+
interface_binding_ident.span,
94+
));
8995
}
9096
}
9197

0 commit comments

Comments
 (0)