diff --git a/__tests__/catch-or-return.js b/__tests__/catch-or-return.js index 4a16fbad..70372ccc 100644 --- a/__tests__/catch-or-return.js +++ b/__tests__/catch-or-return.js @@ -122,7 +122,10 @@ ruleTester.run('catch-or-return', rule, { { code: 'frank().then(go).finally()', options: [{ terminationMethod: ['catch', 'finally'] }] - } + }, + + // for coverage + 'nonPromiseExpressionStatement();' ], invalid: [ diff --git a/__tests__/param-names.js b/__tests__/param-names.js index 6d746717..7a20e9a5 100644 --- a/__tests__/param-names.js +++ b/__tests__/param-names.js @@ -16,7 +16,8 @@ ruleTester.run('param-names', rule, { 'new Promise(function(resolve) {})', 'new Promise(resolve => {})', 'new Promise((resolve, reject) => {})', - 'new Promise(() => {})' + 'new Promise(() => {})', + 'new NonPromise()' ], invalid: [ diff --git a/__tests__/prefer-await-to-callbacks.js b/__tests__/prefer-await-to-callbacks.js index 47e7550d..56f68f43 100644 --- a/__tests__/prefer-await-to-callbacks.js +++ b/__tests__/prefer-await-to-callbacks.js @@ -16,7 +16,8 @@ ruleTester.run('prefer-await-to-callbacks', rule, { 'async function hi() { await thing().then() }', 'async function hi() { await thing().catch() }', 'dbConn.on("error", err => { console.error(err) })', - 'dbConn.once("error", err => { console.error(err) })' + 'dbConn.once("error", err => { console.error(err) })', + 'heart(error => {})' ], invalid: [ diff --git a/__tests__/prefer-await-to-then.js b/__tests__/prefer-await-to-then.js index fefcd165..f143c855 100644 --- a/__tests__/prefer-await-to-then.js +++ b/__tests__/prefer-await-to-then.js @@ -19,7 +19,8 @@ ruleTester.run('prefer-await-to-then', rule, { `a = async () => { try { await something() } catch (error) { somethingElse() } }`, - 'something().then(async () => await somethingElse())' + 'something().then(async () => await somethingElse())', + 'function foo() { hey.somethingElse(x => {}) }' ], invalid: [ diff --git a/package.json b/package.json index bafe4467..f0bf48a7 100644 --- a/package.json +++ b/package.json @@ -58,6 +58,14 @@ "proseWrap": "always" }, "jest": { + "coverageThreshold": { + "global": { + "branches": 100, + "functions": 100, + "lines": 100, + "statements": 100 + } + }, "projects": [ { "displayName": "test", diff --git a/rules/always-return.js b/rules/always-return.js index 5196d1a1..91dbd32b 100644 --- a/rules/always-return.js +++ b/rules/always-return.js @@ -35,6 +35,7 @@ function isInlineThenFunctionExpression(node) { } function hasParentReturnStatement(node) { + // istanbul ignore else -- not reachable given not checking `Program` if (node && node.parent && node.parent.type) { // if the parent is a then, and we haven't returned anything, fail if (isThenCallExpression(node.parent)) { @@ -47,6 +48,7 @@ function hasParentReturnStatement(node) { return hasParentReturnStatement(node.parent) } + // istanbul ignore next -- not reachable given not checking `Program` return false } @@ -139,13 +141,6 @@ module.exports = { return } - // check shortcircuit syntax like `x && x()` and `y || x()`` - const prevSegments = segment.prevSegments - for (let ii = prevSegments.length - 1; ii >= 0; --ii) { - const prevSegment = prevSegments[ii] - if (funcInfo.branchInfoMap[prevSegment.id].good) return - } - context.report({ message: 'Each then() should return a value or throw', node: branch.node diff --git a/rules/lib/has-promise-callback.js b/rules/lib/has-promise-callback.js index 12607f48..8cf07c01 100644 --- a/rules/lib/has-promise-callback.js +++ b/rules/lib/has-promise-callback.js @@ -7,6 +7,7 @@ 'use strict' function hasPromiseCallback(node) { + // istanbul ignore if -- only being called within `CallExpression` if (node.type !== 'CallExpression') return if (node.callee.type !== 'MemberExpression') return const propertyName = node.callee.property.name diff --git a/rules/lib/is-callback.js b/rules/lib/is-callback.js index 7790ac79..2f60b5d3 100644 --- a/rules/lib/is-callback.js +++ b/rules/lib/is-callback.js @@ -2,12 +2,13 @@ const isNamedCallback = require('./is-named-callback') -function isCallingBack(node, exceptions) { +function isCallback(node, exceptions) { const isCallExpression = node.type === 'CallExpression' + // istanbul ignore next -- always invoked on `CallExpression` const callee = node.callee || {} const nameIsCallback = isNamedCallback(callee.name, exceptions) const isCB = isCallExpression && nameIsCallback return isCB } -module.exports = isCallingBack +module.exports = isCallback diff --git a/rules/no-native.js b/rules/no-native.js index 37c16e77..6f36667a 100644 --- a/rules/no-native.js +++ b/rules/no-native.js @@ -11,10 +11,14 @@ function isDeclared(scope, ref) { return false } + // Presumably can't pass this since the implicit `Promise` global + // being checked here would always lack `defs` + // istanbul ignore else if (!variable.defs || !variable.defs.length) { return false } + // istanbul ignore next return true }) } @@ -46,6 +50,7 @@ module.exports = { return } + // istanbul ignore else if (!isDeclared(scope, ref)) { context.report({ node: ref.identifier, diff --git a/rules/no-return-in-finally.js b/rules/no-return-in-finally.js index d3eaa183..9d63bfa3 100644 --- a/rules/no-return-in-finally.js +++ b/rules/no-return-in-finally.js @@ -19,6 +19,7 @@ module.exports = { node.callee.property && node.callee.property.name === 'finally' ) { + // istanbul ignore else -- passing `isPromise` means should have a body if ( node.arguments && node.arguments[0] && diff --git a/rules/valid-params.js b/rules/valid-params.js index 698a0fab..961b0981 100644 --- a/rules/valid-params.js +++ b/rules/valid-params.js @@ -22,6 +22,7 @@ module.exports = { const name = node.callee.property.name const numArgs = node.arguments.length + // istanbul ignore next -- `isPromise` filters out others switch (name) { case 'resolve': case 'reject': @@ -58,6 +59,7 @@ module.exports = { } break default: + // istanbul ignore next -- `isPromise` filters out others break } }