From a8a203201c1bef955bfe4f976e16058b6fcf85d1 Mon Sep 17 00:00:00 2001 From: camc314 <18101008+camc314@users.noreply.github.com> Date: Sat, 22 Nov 2025 19:58:01 +0000 Subject: [PATCH] fix(linter): support missing `range` for internal diagnostics (#15964) --- .../index.ts | 5 +++++ .../tsconfig.base.json | 9 +++++++++ .../tsconfig.json | 3 +++ apps/oxlint/src/lint.rs | 9 +++++++++ ...pe-aware -D no-floating-promises@oxlint.snap | 17 +++++++++++++++++ crates/oxc_linter/src/tsgolint.rs | 17 +++++++++++------ 6 files changed, 54 insertions(+), 6 deletions(-) create mode 100644 apps/oxlint/fixtures/tsgolint_tsconfig_extends_config_err/index.ts create mode 100644 apps/oxlint/fixtures/tsgolint_tsconfig_extends_config_err/tsconfig.base.json create mode 100644 apps/oxlint/fixtures/tsgolint_tsconfig_extends_config_err/tsconfig.json create mode 100644 apps/oxlint/src/snapshots/fixtures__tsgolint_tsconfig_extends_config_err_--type-aware -D no-floating-promises@oxlint.snap diff --git a/apps/oxlint/fixtures/tsgolint_tsconfig_extends_config_err/index.ts b/apps/oxlint/fixtures/tsgolint_tsconfig_extends_config_err/index.ts new file mode 100644 index 0000000000000..9b9b985434d07 --- /dev/null +++ b/apps/oxlint/fixtures/tsgolint_tsconfig_extends_config_err/index.ts @@ -0,0 +1,5 @@ +import { EnumValue } from '~/subdir/enum'; + +const key = EnumValue.Value; + +console.log(key); diff --git a/apps/oxlint/fixtures/tsgolint_tsconfig_extends_config_err/tsconfig.base.json b/apps/oxlint/fixtures/tsgolint_tsconfig_extends_config_err/tsconfig.base.json new file mode 100644 index 0000000000000..c5934dd2d4f3b --- /dev/null +++ b/apps/oxlint/fixtures/tsgolint_tsconfig_extends_config_err/tsconfig.base.json @@ -0,0 +1,9 @@ +{ + "compilerOptions": { + "baseUrl": ".", + "noEmit": true, + "paths": { + "~/*": ["./*"] + } + } +} diff --git a/apps/oxlint/fixtures/tsgolint_tsconfig_extends_config_err/tsconfig.json b/apps/oxlint/fixtures/tsgolint_tsconfig_extends_config_err/tsconfig.json new file mode 100644 index 0000000000000..3ee7a6c6e0360 --- /dev/null +++ b/apps/oxlint/fixtures/tsgolint_tsconfig_extends_config_err/tsconfig.json @@ -0,0 +1,3 @@ +{ + "extends": "./tsconfig.base.json" +} diff --git a/apps/oxlint/src/lint.rs b/apps/oxlint/src/lint.rs index 677882a956bb5..094f5fbd2c147 100644 --- a/apps/oxlint/src/lint.rs +++ b/apps/oxlint/src/lint.rs @@ -1395,4 +1395,13 @@ mod test { let args = &["--type-aware"]; Tester::new().with_cwd("fixtures/tsgolint_config_error".into()).test_and_snapshot(args); } + + #[test] + #[cfg(all(not(target_os = "windows"), not(target_endian = "big")))] + fn test_tsgolint_tsconfig_extends_config_err() { + let args = &["--type-aware", "-D", "no-floating-promises"]; + Tester::new() + .with_cwd("fixtures/tsgolint_tsconfig_extends_config_err".into()) + .test_and_snapshot(args); + } } diff --git a/apps/oxlint/src/snapshots/fixtures__tsgolint_tsconfig_extends_config_err_--type-aware -D no-floating-promises@oxlint.snap b/apps/oxlint/src/snapshots/fixtures__tsgolint_tsconfig_extends_config_err_--type-aware -D no-floating-promises@oxlint.snap new file mode 100644 index 0000000000000..2801f5d349570 --- /dev/null +++ b/apps/oxlint/src/snapshots/fixtures__tsgolint_tsconfig_extends_config_err_--type-aware -D no-floating-promises@oxlint.snap @@ -0,0 +1,17 @@ +--- +source: apps/oxlint/src/tester.rs +--- +########## +arguments: --type-aware -D no-floating-promises +working directory: fixtures/tsgolint_tsconfig_extends_config_err +---------- + + x typescript(tsconfig-error): Invalid tsconfig + help: Option 'baseUrl' has been removed. Please remove it from your configuration. + See https://github.com/oxc-project/tsgolint/issues/351 for more information. + +Found 0 warnings and 1 error. +Finished in ms on 1 file with 103 rules using 1 threads. +---------- +CLI result: LintFoundErrors +---------- diff --git a/crates/oxc_linter/src/tsgolint.rs b/crates/oxc_linter/src/tsgolint.rs index 1a0b00010280d..9eec0b9881343 100644 --- a/crates/oxc_linter/src/tsgolint.rs +++ b/crates/oxc_linter/src/tsgolint.rs @@ -648,7 +648,7 @@ impl<'de> Deserialize<'de> for DiagnosticKind { #[derive(Debug, Clone, Serialize, Deserialize)] struct TsGoLintDiagnosticPayload { pub kind: DiagnosticKind, - pub range: Range, + pub range: Option, pub message: RuleMessage, pub file_path: Option, // Only for kind="rule" @@ -691,7 +691,7 @@ pub struct TsGoLintRuleDiagnostic { #[derive(Debug, Clone)] pub struct TsGoLintInternalDiagnostic { pub message: RuleMessage, - pub range: Range, + pub range: Option, pub file_path: Option, } @@ -727,8 +727,10 @@ impl From for OxcDiagnostic { if let Some(help) = val.message.help { d = d.with_help(help); } - if val.file_path.is_some() { - d = d.with_label(Span::new(val.range.pos, val.range.end)); + if val.file_path.is_some() + && let Some(range) = val.range + { + d = d.with_label(Span::new(range.pos, range.end)); } d } @@ -795,7 +797,7 @@ impl Message { } // TODO: Should this be removed and replaced with a `Span`? -#[derive(Clone, Debug, Serialize, Deserialize)] +#[derive(Clone, Debug, Serialize, Deserialize, Default)] pub struct Range { pub pos: u32, pub end: u32, @@ -989,7 +991,10 @@ fn parse_single_message( rule: diagnostic_payload .rule .expect("Rule name must be present for rule diagnostics"), - range: diagnostic_payload.range, + range: diagnostic_payload.range.unwrap_or_else(|| { + debug_assert!(false, "Range must be present for rule diagnostics"); + Range::default() + }), message: diagnostic_payload.message, fixes: diagnostic_payload.fixes, suggestions: diagnostic_payload.suggestions,