Skip to content

Commit 5f3b854

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 234021f commit 5f3b854

11 files changed

+28
-9
lines changed

__tests__/catch-or-return.js

Lines changed: 3 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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(error => {})',
2021
],
2122

2223
invalid: [

__tests__/prefer-await-to-then.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ ruleTester.run('prefer-await-to-then', rule, {
2020
try { await something() } catch (error) { somethingElse() }
2121
}`,
2222
'something().then(async () => await somethingElse())',
23+
'function foo() { hey.somethingElse(x => {}) }',
2324
],
2425

2526
invalid: [

package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@
5959
"proseWrap": "always"
6060
},
6161
"jest": {
62+
"coverageThreshold": {
63+
"global": {
64+
"branches": 100,
65+
"functions": 100,
66+
"lines": 100,
67+
"statements": 100
68+
}
69+
},
6270
"projects": [
6371
{
6472
"displayName": "test",

rules/always-return.js

Lines changed: 2 additions & 7 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 3 additions & 2 deletions
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

Lines changed: 5 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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] &&

0 commit comments

Comments
 (0)