Skip to content

Commit 54c55b3

Browse files
authored
Merge pull request #196 from brettz9/coverage
Coverage
2 parents 7ac8796 + e09cc0d commit 54c55b3

16 files changed

+9857
-3283
lines changed

CONTRIBUTING.md

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ project, you agree to abide by its terms.
99
## Table of Contents
1010

1111
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
12-
1312
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
1413

1514
- [How can I contribute?](#how-can-i-contribute)

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ or start with the recommended rule set:
9090
| [`no-new-statics`][no-new-statics] | Avoid calling `new` on a Promise static method | :bangbang: | :wrench: |
9191
| [`no-return-in-finally`][no-return-in-finally] | Disallow return statements in `finally()` | :warning: | |
9292
| [`valid-params`][valid-params] | Ensures the proper number of arguments are passed to Promise functions | :warning: | |
93-
| [`prefer-await-to-then`][prefer-await-to-then] | Prefer `await` to `then()` for reading Promise values | :seven: | |
93+
| [`prefer-await-to-then`][prefer-await-to-then] | Prefer `await` to `then()`/`catch()`/`finally()` for reading Promise values | :seven: | |
9494
| [`prefer-await-to-callbacks`][prefer-await-to-callbacks] | Prefer async/await to the callback pattern | :seven: | |
9595

9696
**Key**

__tests__/catch-or-return.js

+3
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ ruleTester.run('catch-or-return', rule, {
123123
code: 'frank().then(go).finally()',
124124
options: [{ terminationMethod: ['catch', 'finally'] }],
125125
},
126+
127+
// for coverage
128+
'nonPromiseExpressionStatement();',
126129
],
127130

128131
invalid: [

__tests__/param-names.js

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ ruleTester.run('param-names', rule, {
1717
'new Promise(resolve => {})',
1818
'new Promise((resolve, reject) => {})',
1919
'new Promise(() => {})',
20+
'new NonPromise()',
2021
],
2122

2223
invalid: [

__tests__/prefer-await-to-callbacks.js

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ ruleTester.run('prefer-await-to-callbacks', rule, {
1717
'async function hi() { await thing().catch() }',
1818
'dbConn.on("error", err => { console.error(err) })',
1919
'dbConn.once("error", err => { console.error(err) })',
20+
'heart(something => {})',
2021
],
2122

2223
invalid: [

__tests__/prefer-await-to-then.js

+14-2
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,19 @@ const ruleTester = new RuleTester({
88
},
99
})
1010

11-
const message = 'Prefer await to then().'
11+
const message = 'Prefer await to then()/catch()/finally().'
1212

1313
ruleTester.run('prefer-await-to-then', rule, {
1414
valid: [
1515
'async function hi() { await thing() }',
1616
'async function hi() { await thing().then() }',
1717
'async function hi() { await thing().catch() }',
1818
'a = async () => (await something())',
19+
`a = async () => {
20+
try { await something() } catch (error) { somethingElse() }
21+
}`,
1922
'something().then(async () => await somethingElse())',
23+
'function foo() { hey.somethingElse(x => {}) }',
2024
],
2125

2226
invalid: [
@@ -30,12 +34,20 @@ ruleTester.run('prefer-await-to-then', rule, {
3034
},
3135
{
3236
code: 'function foo() { hey.then(function() { }).then(x).catch() }',
33-
errors: [{ message }, { message }],
37+
errors: [{ message }, { message }, { message }],
3438
},
3539
{
3640
code:
3741
'async function a() { hey.then(function() { }).then(function() { }) }',
3842
errors: [{ message }, { message }],
3943
},
44+
{
45+
code: 'function foo() { hey.catch(x => {}) }',
46+
errors: [{ message }],
47+
},
48+
{
49+
code: 'function foo() { hey.finally(x => {}) }',
50+
errors: [{ message }],
51+
},
4052
],
4153
})

docs/rules/prefer-await-to-then.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Prefer `await` to `then()` for reading Promise values (prefer-await-to-then)
1+
# Prefer `await` to `then()`/`catch()`/`finally()` for reading Promise values (prefer-await-to-then)
22

33
#### Valid
44

@@ -33,4 +33,14 @@ function exampleTwo() {
3333
.then(doSomethingElseAsync)
3434
.catch(errors)
3535
}
36+
37+
function exampleThree() {
38+
return myPromise
39+
.catch(errors)
40+
}
41+
42+
function exampleFour() {
43+
return myPromise
44+
.finally(cleanup)
45+
}
3646
```

0 commit comments

Comments
 (0)