Skip to content

Commit 757b67f

Browse files
committed
- Testing: Get to 100% coverage
Also: - internally renames `isCallingBack` to `isCallback` as per file name and usage - removed code block from `always-return` which is not necessary given that "good" return/throw statements cannot occur within shortcut syntax (which expect expressions)
1 parent 8804f46 commit 757b67f

11 files changed

+32
-13
lines changed

__tests__/catch-or-return.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,10 @@ ruleTester.run('catch-or-return', rule, {
122122
{
123123
code: 'frank().then(go).finally()',
124124
options: [{ terminationMethod: ['catch', 'finally'] }]
125-
}
125+
},
126+
127+
// for coverage
128+
'nonPromiseExpressionStatement();'
126129
],
127130

128131
invalid: [

__tests__/param-names.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ ruleTester.run('param-names', rule, {
1616
'new Promise(function(resolve) {})',
1717
'new Promise(resolve => {})',
1818
'new Promise((resolve, reject) => {})',
19-
'new Promise(() => {})'
19+
'new Promise(() => {})',
20+
'new NonPromise()'
2021
],
2122

2223
invalid: [

__tests__/prefer-await-to-callbacks.js

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

2223
invalid: [

__tests__/prefer-await-to-then.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ ruleTester.run('prefer-await-to-then', rule, {
1919
`a = async () => {
2020
try { await something() } catch (error) { somethingElse() }
2121
}`,
22-
'something().then(async () => await somethingElse())'
22+
'something().then(async () => await somethingElse())',
23+
'function foo() { hey.somethingElse(x => {}) }'
2324
],
2425

2526
invalid: [

package.json

+8
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@
5858
"proseWrap": "always"
5959
},
6060
"jest": {
61+
"coverageThreshold": {
62+
"global": {
63+
"branches": 100,
64+
"functions": 100,
65+
"lines": 100,
66+
"statements": 100
67+
}
68+
},
6169
"projects": [
6270
{
6371
"displayName": "test",

rules/always-return.js

+2-7
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ function isInlineThenFunctionExpression(node) {
3535
}
3636

3737
function hasParentReturnStatement(node) {
38+
// istanbul ignore else -- not reachable given not checking `Program`
3839
if (node && node.parent && node.parent.type) {
3940
// if the parent is a then, and we haven't returned anything, fail
4041
if (isThenCallExpression(node.parent)) {
@@ -47,6 +48,7 @@ function hasParentReturnStatement(node) {
4748
return hasParentReturnStatement(node.parent)
4849
}
4950

51+
// istanbul ignore next -- not reachable given not checking `Program`
5052
return false
5153
}
5254

@@ -139,13 +141,6 @@ module.exports = {
139141
return
140142
}
141143

142-
// check shortcircuit syntax like `x && x()` and `y || x()``
143-
const prevSegments = segment.prevSegments
144-
for (let ii = prevSegments.length - 1; ii >= 0; --ii) {
145-
const prevSegment = prevSegments[ii]
146-
if (funcInfo.branchInfoMap[prevSegment.id].good) return
147-
}
148-
149144
context.report({
150145
message: 'Each then() should return a value or throw',
151146
node: branch.node

rules/lib/has-promise-callback.js

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
'use strict'
88

99
function hasPromiseCallback(node) {
10+
// istanbul ignore if -- only being called within `CallExpression`
1011
if (node.type !== 'CallExpression') return
1112
if (node.callee.type !== 'MemberExpression') return
1213
const propertyName = node.callee.property.name

rules/lib/is-callback.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22

33
const isNamedCallback = require('./is-named-callback')
44

5-
function isCallingBack(node, exceptions) {
5+
function isCallback(node, exceptions) {
66
const isCallExpression = node.type === 'CallExpression'
7+
// istanbul ignore next -- always invoked on `CallExpression`
78
const callee = node.callee || {}
89
const nameIsCallback = isNamedCallback(callee.name, exceptions)
910
const isCB = isCallExpression && nameIsCallback
1011
return isCB
1112
}
1213

13-
module.exports = isCallingBack
14+
module.exports = isCallback

rules/no-native.js

+5
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@ function isDeclared(scope, ref) {
1111
return false
1212
}
1313

14+
// Presumably can't pass this since the implicit `Promise` global
15+
// being checked here would always lack `defs`
16+
// istanbul ignore else
1417
if (!variable.defs || !variable.defs.length) {
1518
return false
1619
}
1720

21+
// istanbul ignore next
1822
return true
1923
})
2024
}
@@ -46,6 +50,7 @@ module.exports = {
4650
return
4751
}
4852

53+
// istanbul ignore else
4954
if (!isDeclared(scope, ref)) {
5055
context.report({
5156
node: ref.identifier,

rules/no-return-in-finally.js

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ module.exports = {
1919
node.callee.property &&
2020
node.callee.property.name === 'finally'
2121
) {
22+
// istanbul ignore else -- passing `isPromise` means should have a body
2223
if (
2324
node.arguments &&
2425
node.arguments[0] &&

rules/valid-params.js

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ module.exports = {
2222
const name = node.callee.property.name
2323
const numArgs = node.arguments.length
2424

25+
// istanbul ignore next -- `isPromise` filters out others
2526
switch (name) {
2627
case 'resolve':
2728
case 'reject':
@@ -58,6 +59,7 @@ module.exports = {
5859
}
5960
break
6061
default:
62+
// istanbul ignore next -- `isPromise` filters out others
6163
break
6264
}
6365
}

0 commit comments

Comments
 (0)