Skip to content

Commit d8d8f64

Browse files
committed
fix(linter): shorten span of promise/prefer-await-to-then (#10717)
closes #8672
1 parent a88e349 commit d8d8f64

File tree

2 files changed

+32
-27
lines changed

2 files changed

+32
-27
lines changed

crates/oxc_linter/src/rules/promise/prefer_await_to_then.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,12 @@ impl Rule for PreferAwaitToThen {
9393
}
9494
}
9595

96-
ctx.diagnostic(prefer_wait_to_then_diagnostic(call_expr.span));
96+
let span = call_expr
97+
.callee
98+
.as_member_expression()
99+
.and_then(oxc_ast::ast::MemberExpression::static_property_info)
100+
.map_or(call_expr.span, |(span, _)| span);
101+
ctx.diagnostic(prefer_wait_to_then_diagnostic(span));
97102
}
98103
}
99104

crates/oxc_linter/src/snapshots/promise_prefer_await_to_then.snap

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,79 +2,79 @@
22
source: crates/oxc_linter/src/tester.rs
33
---
44
eslint-plugin-promise(prefer-await-to-then): Prefer await to then()/catch()/finally()
5-
╭─[prefer_await_to_then.tsx:1:18]
5+
╭─[prefer_await_to_then.tsx:1:22]
66
1function foo() { hey.then(x => {}) }
7-
· ─────────────────
7+
· ────
88
╰────
99

1010
eslint-plugin-promise(prefer-await-to-then): Prefer await to then()/catch()/finally()
11-
╭─[prefer_await_to_then.tsx:1:18]
11+
╭─[prefer_await_to_then.tsx:1:43]
1212
1function foo() { hey.then(function() { }).then() }
13-
· ───────────────────────────────
13+
· ────
1414
╰────
1515

1616
eslint-plugin-promise(prefer-await-to-then): Prefer await to then()/catch()/finally()
17-
╭─[prefer_await_to_then.tsx:1:18]
17+
╭─[prefer_await_to_then.tsx:1:22]
1818
1function foo() { hey.then(function() { }).then() }
19-
· ────────────────────────
19+
· ────
2020
╰────
2121

2222
eslint-plugin-promise(prefer-await-to-then): Prefer await to then()/catch()/finally()
23-
╭─[prefer_await_to_then.tsx:1:18]
23+
╭─[prefer_await_to_then.tsx:1:51]
2424
1function foo() { hey.then(function() { }).then(x).catch() }
25-
· ────────────────────────────────────────
25+
· ─────
2626
╰────
2727

2828
eslint-plugin-promise(prefer-await-to-then): Prefer await to then()/catch()/finally()
29-
╭─[prefer_await_to_then.tsx:1:18]
29+
╭─[prefer_await_to_then.tsx:1:43]
3030
1function foo() { hey.then(function() { }).then(x).catch() }
31-
· ────────────────────────────────
31+
· ────
3232
╰────
3333

3434
eslint-plugin-promise(prefer-await-to-then): Prefer await to then()/catch()/finally()
35-
╭─[prefer_await_to_then.tsx:1:18]
35+
╭─[prefer_await_to_then.tsx:1:22]
3636
1function foo() { hey.then(function() { }).then(x).catch() }
37-
· ────────────────────────
37+
· ────
3838
╰────
3939

4040
eslint-plugin-promise(prefer-await-to-then): Prefer await to then()/catch()/finally()
41-
╭─[prefer_await_to_then.tsx:1:22]
41+
╭─[prefer_await_to_then.tsx:1:47]
4242
1async function a() { hey.then(function() { }).then(function() { }) }
43-
· ─────────────────────────────────────────────
43+
· ────
4444
╰────
4545

4646
eslint-plugin-promise(prefer-await-to-then): Prefer await to then()/catch()/finally()
47-
╭─[prefer_await_to_then.tsx:1:22]
47+
╭─[prefer_await_to_then.tsx:1:26]
4848
1async function a() { hey.then(function() { }).then(function() { }) }
49-
· ────────────────────────
49+
· ────
5050
╰────
5151

5252
eslint-plugin-promise(prefer-await-to-then): Prefer await to then()/catch()/finally()
53-
╭─[prefer_await_to_then.tsx:1:18]
53+
╭─[prefer_await_to_then.tsx:1:22]
5454
1function foo() { hey.catch(x => {}) }
55-
· ──────────────────
55+
· ─────
5656
╰────
5757

5858
eslint-plugin-promise(prefer-await-to-then): Prefer await to then()/catch()/finally()
59-
╭─[prefer_await_to_then.tsx:1:18]
59+
╭─[prefer_await_to_then.tsx:1:22]
6060
1function foo() { hey.finally(x => {}) }
61-
· ────────────────────
61+
· ───────
6262
╰────
6363

6464
eslint-plugin-promise(prefer-await-to-then): Prefer await to then()/catch()/finally()
65-
╭─[prefer_await_to_then.tsx:1:1]
65+
╭─[prefer_await_to_then.tsx:1:13]
6666
1something().then(async () => await somethingElse())
67-
· ───────────────────────────────────────────────────
67+
· ────
6868
╰────
6969

7070
eslint-plugin-promise(prefer-await-to-then): Prefer await to then()/catch()/finally()
71-
╭─[prefer_await_to_then.tsx:1:30]
71+
╭─[prefer_await_to_then.tsx:1:38]
7272
1async function foo() { await thing().then() }
73-
· ──────────────
73+
· ────
7474
╰────
7575

7676
eslint-plugin-promise(prefer-await-to-then): Prefer await to then()/catch()/finally()
77-
╭─[prefer_await_to_then.tsx:1:24]
77+
╭─[prefer_await_to_then.tsx:1:32]
7878
1async function foo() { thing().then() }
79-
· ──────────────
79+
· ────
8080
╰────

0 commit comments

Comments
 (0)