Skip to content

Commit a8a2032

Browse files
committed
fix(linter): support missing range for internal diagnostics (#15964)
1 parent 9540000 commit a8a2032

File tree

6 files changed

+54
-6
lines changed

6 files changed

+54
-6
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { EnumValue } from '~/subdir/enum';
2+
3+
const key = EnumValue.Value;
4+
5+
console.log(key);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"compilerOptions": {
3+
"baseUrl": ".",
4+
"noEmit": true,
5+
"paths": {
6+
"~/*": ["./*"]
7+
}
8+
}
9+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "./tsconfig.base.json"
3+
}

apps/oxlint/src/lint.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,4 +1395,13 @@ mod test {
13951395
let args = &["--type-aware"];
13961396
Tester::new().with_cwd("fixtures/tsgolint_config_error".into()).test_and_snapshot(args);
13971397
}
1398+
1399+
#[test]
1400+
#[cfg(all(not(target_os = "windows"), not(target_endian = "big")))]
1401+
fn test_tsgolint_tsconfig_extends_config_err() {
1402+
let args = &["--type-aware", "-D", "no-floating-promises"];
1403+
Tester::new()
1404+
.with_cwd("fixtures/tsgolint_tsconfig_extends_config_err".into())
1405+
.test_and_snapshot(args);
1406+
}
13981407
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
source: apps/oxlint/src/tester.rs
3+
---
4+
##########
5+
arguments: --type-aware -D no-floating-promises
6+
working directory: fixtures/tsgolint_tsconfig_extends_config_err
7+
----------
8+
9+
x typescript(tsconfig-error): Invalid tsconfig
10+
help: Option 'baseUrl' has been removed. Please remove it from your configuration.
11+
See https://github.com/oxc-project/tsgolint/issues/351 for more information.
12+
13+
Found 0 warnings and 1 error.
14+
Finished in <variable>ms on 1 file with 103 rules using 1 threads.
15+
----------
16+
CLI result: LintFoundErrors
17+
----------

crates/oxc_linter/src/tsgolint.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ impl<'de> Deserialize<'de> for DiagnosticKind {
648648
#[derive(Debug, Clone, Serialize, Deserialize)]
649649
struct TsGoLintDiagnosticPayload {
650650
pub kind: DiagnosticKind,
651-
pub range: Range,
651+
pub range: Option<Range>,
652652
pub message: RuleMessage,
653653
pub file_path: Option<String>,
654654
// Only for kind="rule"
@@ -691,7 +691,7 @@ pub struct TsGoLintRuleDiagnostic {
691691
#[derive(Debug, Clone)]
692692
pub struct TsGoLintInternalDiagnostic {
693693
pub message: RuleMessage,
694-
pub range: Range,
694+
pub range: Option<Range>,
695695
pub file_path: Option<PathBuf>,
696696
}
697697

@@ -727,8 +727,10 @@ impl From<TsGoLintInternalDiagnostic> for OxcDiagnostic {
727727
if let Some(help) = val.message.help {
728728
d = d.with_help(help);
729729
}
730-
if val.file_path.is_some() {
731-
d = d.with_label(Span::new(val.range.pos, val.range.end));
730+
if val.file_path.is_some()
731+
&& let Some(range) = val.range
732+
{
733+
d = d.with_label(Span::new(range.pos, range.end));
732734
}
733735
d
734736
}
@@ -795,7 +797,7 @@ impl Message {
795797
}
796798

797799
// TODO: Should this be removed and replaced with a `Span`?
798-
#[derive(Clone, Debug, Serialize, Deserialize)]
800+
#[derive(Clone, Debug, Serialize, Deserialize, Default)]
799801
pub struct Range {
800802
pub pos: u32,
801803
pub end: u32,
@@ -989,7 +991,10 @@ fn parse_single_message(
989991
rule: diagnostic_payload
990992
.rule
991993
.expect("Rule name must be present for rule diagnostics"),
992-
range: diagnostic_payload.range,
994+
range: diagnostic_payload.range.unwrap_or_else(|| {
995+
debug_assert!(false, "Range must be present for rule diagnostics");
996+
Range::default()
997+
}),
993998
message: diagnostic_payload.message,
994999
fixes: diagnostic_payload.fixes,
9951000
suggestions: diagnostic_payload.suggestions,

0 commit comments

Comments
 (0)