Skip to content

Commit

Permalink
Merge pull request #196 from brettz9/coverage
Browse files Browse the repository at this point in the history
Coverage
  • Loading branch information
xjamundx committed Apr 9, 2021
2 parents 7ac8796 + e09cc0d commit 54c55b3
Show file tree
Hide file tree
Showing 16 changed files with 9,857 additions and 3,283 deletions.
1 change: 0 additions & 1 deletion CONTRIBUTING.md
Expand Up @@ -9,7 +9,6 @@ project, you agree to abide by its terms.
## Table of Contents

<!-- START doctoc generated TOC please keep comment here to allow auto update -->

<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->

- [How can I contribute?](#how-can-i-contribute)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -90,7 +90,7 @@ or start with the recommended rule set:
| [`no-new-statics`][no-new-statics] | Avoid calling `new` on a Promise static method | :bangbang: | :wrench: |
| [`no-return-in-finally`][no-return-in-finally] | Disallow return statements in `finally()` | :warning: | |
| [`valid-params`][valid-params] | Ensures the proper number of arguments are passed to Promise functions | :warning: | |
| [`prefer-await-to-then`][prefer-await-to-then] | Prefer `await` to `then()` for reading Promise values | :seven: | |
| [`prefer-await-to-then`][prefer-await-to-then] | Prefer `await` to `then()`/`catch()`/`finally()` for reading Promise values | :seven: | |
| [`prefer-await-to-callbacks`][prefer-await-to-callbacks] | Prefer async/await to the callback pattern | :seven: | |

**Key**
Expand Down
3 changes: 3 additions & 0 deletions __tests__/catch-or-return.js
Expand Up @@ -123,6 +123,9 @@ ruleTester.run('catch-or-return', rule, {
code: 'frank().then(go).finally()',
options: [{ terminationMethod: ['catch', 'finally'] }],
},

// for coverage
'nonPromiseExpressionStatement();',
],

invalid: [
Expand Down
1 change: 1 addition & 0 deletions __tests__/param-names.js
Expand Up @@ -17,6 +17,7 @@ ruleTester.run('param-names', rule, {
'new Promise(resolve => {})',
'new Promise((resolve, reject) => {})',
'new Promise(() => {})',
'new NonPromise()',
],

invalid: [
Expand Down
1 change: 1 addition & 0 deletions __tests__/prefer-await-to-callbacks.js
Expand Up @@ -17,6 +17,7 @@ ruleTester.run('prefer-await-to-callbacks', rule, {
'async function hi() { await thing().catch() }',
'dbConn.on("error", err => { console.error(err) })',
'dbConn.once("error", err => { console.error(err) })',
'heart(something => {})',
],

invalid: [
Expand Down
16 changes: 14 additions & 2 deletions __tests__/prefer-await-to-then.js
Expand Up @@ -8,15 +8,19 @@ const ruleTester = new RuleTester({
},
})

const message = 'Prefer await to then().'
const message = 'Prefer await to then()/catch()/finally().'

ruleTester.run('prefer-await-to-then', rule, {
valid: [
'async function hi() { await thing() }',
'async function hi() { await thing().then() }',
'async function hi() { await thing().catch() }',
'a = async () => (await something())',
`a = async () => {
try { await something() } catch (error) { somethingElse() }
}`,
'something().then(async () => await somethingElse())',
'function foo() { hey.somethingElse(x => {}) }',
],

invalid: [
Expand All @@ -30,12 +34,20 @@ ruleTester.run('prefer-await-to-then', rule, {
},
{
code: 'function foo() { hey.then(function() { }).then(x).catch() }',
errors: [{ message }, { message }],
errors: [{ message }, { message }, { message }],
},
{
code:
'async function a() { hey.then(function() { }).then(function() { }) }',
errors: [{ message }, { message }],
},
{
code: 'function foo() { hey.catch(x => {}) }',
errors: [{ message }],
},
{
code: 'function foo() { hey.finally(x => {}) }',
errors: [{ message }],
},
],
})
12 changes: 11 additions & 1 deletion docs/rules/prefer-await-to-then.md
@@ -1,4 +1,4 @@
# Prefer `await` to `then()` for reading Promise values (prefer-await-to-then)
# Prefer `await` to `then()`/`catch()`/`finally()` for reading Promise values (prefer-await-to-then)

#### Valid

Expand Down Expand Up @@ -33,4 +33,14 @@ function exampleTwo() {
.then(doSomethingElseAsync)
.catch(errors)
}

function exampleThree() {
return myPromise
.catch(errors)
}

function exampleFour() {
return myPromise
.finally(cleanup)
}
```

0 comments on commit 54c55b3

Please sign in to comment.