Skip to content

Commit 97c9a13

Browse files
committed
fix(linter/type-aware): use correct span for disable directives
1 parent 89b58d0 commit 97c9a13

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
11
declare const b1: object;
22
declare const b2: boolean;
33
export const t1 = b1 && b2;
4+
5+
function checkNumber(x: number) {
6+
// eslint-disable-next-line typescript/no-unnecessary-condition
7+
if (x != null) {
8+
return x;
9+
}
10+
return 0;
11+
}
12+
13+
checkNumber(1);

apps/oxlint/src/snapshots/fixtures__tsgolint_--type-aware@oxlint.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,15 @@ working directory: fixtures/tsgolint
165165
2 | declare const b2: boolean;
166166
3 | export const t1 = b1 && b2;
167167
: ^^
168+
4 |
168169
`----
169170
170171
x typescript-eslint(strict-boolean-expressions): Unexpected object value in conditional. An object is always truthy.
171172
,-[no-unnecessary-condition.ts:3:19]
172173
2 | declare const b2: boolean;
173174
3 | export const t1 = b1 && b2;
174175
: ^^
176+
4 |
175177
`----
176178
177179
x typescript-eslint(no-unnecessary-qualifier): Qualifier is unnecessary since 'B' is in scope.

crates/oxc_linter/src/tsgolint.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1059,7 +1059,10 @@ fn should_skip_diagnostic(
10591059
path: &Path,
10601060
tsgolint_diagnostic: &TsGoLintRuleDiagnostic,
10611061
) -> bool {
1062-
let span = tsgolint_diagnostic.span;
1062+
let span = tsgolint_diagnostic
1063+
.labeled_ranges
1064+
.first()
1065+
.map_or(tsgolint_diagnostic.span, |range| Span::new(range.range.pos, range.range.end));
10631066

10641067
if let Some(directives) = disable_directives_map.get(path) {
10651068
directives.contains(&tsgolint_diagnostic.rule, span)

0 commit comments

Comments
 (0)