Skip to content

Commit 73fe248

Browse files
committedMar 18, 2025
fix(linter/no_case_declarations): fix span of error for await using (#9854)
Follow-on after #9751. Make the span in error for `await using` more accurate.
1 parent bc8bc08 commit 73fe248

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed
 

‎crates/oxc_linter/src/rules/eslint/no_case_declarations.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,18 @@ impl Rule for NoCaseDeclarations {
6464
}
6565
Statement::VariableDeclaration(var) if var.kind.is_lexical() => {
6666
let start = var.span.start;
67-
let end = match var.kind {
67+
let len = match var.kind {
6868
VariableDeclarationKind::Const | VariableDeclarationKind::Using => 5,
6969
VariableDeclarationKind::Let => 3,
70+
#[expect(clippy::cast_possible_truncation)]
7071
VariableDeclarationKind::AwaitUsing => {
71-
var.declarations[0].span.start - start
72+
ctx.source_range(Span::new(start, var.declarations[0].span.start))
73+
.trim_end()
74+
.len() as u32
7275
}
7376
VariableDeclarationKind::Var => unreachable!(),
7477
};
75-
let end = start + end;
78+
let end = start + len;
7679
ctx.diagnostic(no_case_declarations_diagnostic(Span::new(start, end)));
7780
}
7881
_ => {}

‎crates/oxc_linter/src/snapshots/eslint_no_case_declarations.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,5 @@ source: crates/oxc_linter/src/tester.rs
5858
eslint(no-case-declarations): Unexpected lexical declaration in case block.
5959
╭─[no_case_declarations.tsx:1:23]
6060
1switch (a) { default: await using x = {}; break; }
61-
· ───────────
61+
· ───────────
6262
╰────

0 commit comments

Comments
 (0)