Skip to content

Commit 9c427f8

Browse files
Add missing test cases for .catch
1 parent 485a9b0 commit 9c427f8

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

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

+4-8
Original file line numberDiff line numberDiff line change
@@ -32,26 +32,20 @@ declare_oxc_lint!(
3232
/// Examples of **incorrect** code for this rule:
3333
/// ```javascript
3434
/// doThing().then(() => a.then())
35-
/// ```
3635
///
37-
/// ```javascript
3836
/// doThing().then(function() { a.then() })
39-
/// ```
4037
///
41-
/// ```javascript
4238
/// doThing().then(() => { b.catch() })
39+
///
40+
/// doThing().catch((val) => doSomething(val).catch(errors))
4341
/// ```
4442
///
4543
/// Examples of **correct** code for this rule:
4644
/// ```javascript
4745
/// doThing().then(() => 4)
48-
/// ```
4946
///
50-
/// ```javascript
5147
/// doThing().then(function() { return 4 })
52-
/// ```
5348
///
54-
/// ```javascript
5549
/// doThing().catch(() => 4)
5650
/// ```
5751
///
@@ -273,6 +267,8 @@ fn test() {
273267
"doThing().then(() => { b.catch() })",
274268
"doThing().then(() => a.then())",
275269
"doThing().then(() => b.catch())",
270+
"doThing().then((val) => doSomething(val).catch(errors))",
271+
"doThing().catch((val) => doSomething(val).catch(errors))",
276272
"doThing()
277273
.then(() =>
278274
a.then(() => Promise.resolve(1)))",

crates/oxc_linter/src/snapshots/promise_no_nesting.snap

+14
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,20 @@ source: crates/oxc_linter/src/tester.rs
5757
╰────
5858
help: Refactor so that promises are chained in a flat manner.
5959

60+
eslint-plugin-promise(no-nesting): Avoid nesting promises.
61+
╭─[no_nesting.tsx:1:25]
62+
1doThing().then((val) => doSomething(val).catch(errors))
63+
· ──────────────────────
64+
╰────
65+
help: Refactor so that promises are chained in a flat manner.
66+
67+
eslint-plugin-promise(no-nesting): Avoid nesting promises.
68+
╭─[no_nesting.tsx:1:26]
69+
1doThing().catch((val) => doSomething(val).catch(errors))
70+
· ──────────────────────
71+
╰────
72+
help: Refactor so that promises are chained in a flat manner.
73+
6074
eslint-plugin-promise(no-nesting): Avoid nesting promises.
6175
╭─[no_nesting.tsx:3:13]
6276
2 │ .then(() =>

0 commit comments

Comments
 (0)