diff --git a/apps/oxlint/fixtures/cli/tsgolint_disable_directives/no-unnecessary-type-parameters-disable.ts b/apps/oxlint/fixtures/cli/tsgolint_disable_directives/no-unnecessary-type-parameters-disable.ts new file mode 100644 index 0000000000000..bdb5d548b738f --- /dev/null +++ b/apps/oxlint/fixtures/cli/tsgolint_disable_directives/no-unnecessary-type-parameters-disable.ts @@ -0,0 +1,8 @@ +// This disable directive is USED even when the tsgolint diagnostic has labeled ranges. +// oxlint-disable-next-line typescript/no-unnecessary-type-parameters +export function parseYAML( + input: string, +): T { + // oxlint-disable-next-line typescript/no-unsafe-type-assertion + return input as any as T; +} diff --git a/apps/oxlint/src/lint.rs b/apps/oxlint/src/lint.rs index 4aa282f0b6026..d79c139ffacfd 100644 --- a/apps/oxlint/src/lint.rs +++ b/apps/oxlint/src/lint.rs @@ -1435,7 +1435,7 @@ mod test { #[test] fn test_tsgolint_disable_directives() { // Test that disable directives work with type-aware rules - let args = &["--type-aware", "test.ts"]; + let args = &["--type-aware"]; Tester::new() .with_cwd("fixtures/cli/tsgolint_disable_directives".into()) .test_and_snapshot(args); diff --git a/apps/oxlint/src/snapshots/fixtures__cli__tsgolint_disable_directives_--type-aware test.ts@oxlint.snap b/apps/oxlint/src/snapshots/fixtures__cli__tsgolint_disable_directives_--type-aware@oxlint.snap similarity index 63% rename from apps/oxlint/src/snapshots/fixtures__cli__tsgolint_disable_directives_--type-aware test.ts@oxlint.snap rename to apps/oxlint/src/snapshots/fixtures__cli__tsgolint_disable_directives_--type-aware@oxlint.snap index 4754a2be177cb..173b7e0885dc2 100644 --- a/apps/oxlint/src/snapshots/fixtures__cli__tsgolint_disable_directives_--type-aware test.ts@oxlint.snap +++ b/apps/oxlint/src/snapshots/fixtures__cli__tsgolint_disable_directives_--type-aware@oxlint.snap @@ -2,7 +2,7 @@ source: apps/oxlint/src/tester.rs --- ########## -arguments: --type-aware test.ts +arguments: --type-aware working directory: fixtures/cli/tsgolint_disable_directives ---------- @@ -95,8 +95,54 @@ working directory: fixtures/cli/tsgolint_disable_directives `---- help: The promise must end with a call to .catch, or end with a call to .then with a rejection handler, or be explicitly marked as ignored with the `void` operator. -Found 10 warnings and 0 errors. -Finished in ms on 1 file with 107 rules using 1 threads. + ! eslint(no-unused-expressions): Expected expression to be used + ,-[unused.ts:6:1] + 5 | // oxlint-disable-next-line typescript/no-floating-promises + 6 | myPromise + : ^^^^^^^^^ + 7 | + `---- + help: Consider using this expression or removing it + + ! eslint(no-unused-expressions): Expected expression to be used + ,-[unused.ts:14:1] + 13 | // oxlint-disable-next-line typescript/no-unsafe-assignment + 14 | myPromise + : ^^^^^^^^^ + 15 | + `---- + help: Consider using this expression or removing it + + ! typescript-eslint(no-floating-promises): Promises must be awaited, add void operator to ignore. + ,-[unused.ts:14:1] + 13 | // oxlint-disable-next-line typescript/no-unsafe-assignment + 14 | myPromise + : ^^^^^^^^^ + 15 | + `---- + help: The promise must end with a call to .catch, or end with a call to .then with a rejection handler, or be explicitly marked as ignored with the `void` operator. + + ! eslint(no-unused-expressions): Expected expression to be used + ,-[unused.ts:18:1] + 17 | /* eslint-disable @typescript-eslint/no-floating-promises */ + 18 | myPromise + : ^^^^^^^^^ + 19 | /* eslint-enable @typescript-eslint/no-floating-promises */ + `---- + help: Consider using this expression or removing it + + ! eslint(no-unused-vars): Variable 'x' is declared but never used. Unused variables should start with a '_'. + ,-[unused.ts:23:7] + 22 | /* eslint-disable @typescript-eslint/no-floating-promises */ + 23 | const x = 1 + 2 + : | + : `-- 'x' is declared here + 24 | /* eslint-enable @typescript-eslint/no-floating-promises */ + `---- + help: Consider removing this declaration. + +Found 15 warnings and 0 errors. +Finished in ms on 3 files with 107 rules using 1 threads. ---------- CLI result: LintSucceeded ---------- diff --git a/crates/oxc_linter/src/tsgolint.rs b/crates/oxc_linter/src/tsgolint.rs index 01bf19d621fce..de98e830d4c69 100644 --- a/crates/oxc_linter/src/tsgolint.rs +++ b/crates/oxc_linter/src/tsgolint.rs @@ -1059,10 +1059,14 @@ fn should_skip_diagnostic( path: &Path, tsgolint_diagnostic: &TsGoLintRuleDiagnostic, ) -> bool { - let span = tsgolint_diagnostic - .labeled_ranges - .first() - .map_or(tsgolint_diagnostic.span, |range| Span::new(range.range.pos, range.range.end)); + let span = if tsgolint_diagnostic.span.is_unspanned() { + tsgolint_diagnostic + .labeled_ranges + .first() + .map_or(tsgolint_diagnostic.span, |range| Span::new(range.range.pos, range.range.end)) + } else { + tsgolint_diagnostic.span + }; if let Some(directives) = disable_directives_map.get(path) { directives.contains(&tsgolint_diagnostic.rule, span)