Skip to content

Commit 3af1e5d

Browse files
committed
fix(linter/no-unsafe-declaration-merging): always mark first span as primary (#13830)
This is technically a breaking change, but more closely aligns our implementation with typescript-eslint, and makes placement of the disable directive more predictable. Previously, it was unclear where the disable directive should go (on the clase or on the interface), this PR enforces that the directive must go on the `class`.
1 parent 395d40d commit 3af1e5d

File tree

8 files changed

+37
-26
lines changed

8 files changed

+37
-26
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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// oxlint-disable-next-line typescript/no-unsafe-declaration-merging
2+
export interface Component {}
3+
4+
export abstract class Component {}
5+
6+
// oxlint-disable-next-line typescript/no-unsafe-declaration-merging
7+
export abstract class Component2 {}
8+
9+
export interface Component2 {}

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::{
1313
fn no_unsafe_declaration_merging_diagnostic(span: Span, span1: Span) -> OxcDiagnostic {
1414
OxcDiagnostic::warn("Unsafe declaration merging between classes and interfaces.")
1515
.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])
16+
.with_labels(if span < span1 { [span, span1]} else { [span1, span] })
1717
}
1818

1919
#[derive(Debug, Default, Clone)]

0 commit comments

Comments
 (0)