From b18e8ba24fa52c6e78b9c16c498e8cd91f2db3d0 Mon Sep 17 00:00:00 2001 From: Paul Melnikow Date: Wed, 13 Jul 2016 18:39:20 -0400 Subject: [PATCH] Fix for it.only --- lib/rules/no-mocha-global-arrows.js | 16 ++++++++++++---- test/rules/no-mocha-global-arrows.js | 8 +++++++- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/lib/rules/no-mocha-global-arrows.js b/lib/rules/no-mocha-global-arrows.js index b54638c..674a884 100644 --- a/lib/rules/no-mocha-global-arrows.js +++ b/lib/rules/no-mocha-global-arrows.js @@ -29,20 +29,28 @@ var R = require('ramda'), ]; module.exports = function (context) { + function getCalleeName(callee) { + if (callee.type === 'MemberExpression') { + return callee.object.name + '.' + callee.property.name; + } + + return callee.name; + } + function isLikelyMochaGlobal(scope, name) { return !R.find(R.propEq('name', name), scope.variables); } return { CallExpression: function (node) { - var callee = node.callee, + var name = getCalleeName(node.callee), fnArg; - if (callee && callee.name && mochaFunctionNames.indexOf(callee.name) > -1) { + if (name && mochaFunctionNames.indexOf(name) > -1) { fnArg = node.arguments.slice(-1)[0]; if (fnArg && fnArg.type === 'ArrowFunctionExpression') { - if (isLikelyMochaGlobal(context.getScope(), callee.name)) { - context.report(node, 'Do not pass arrow functions to ' + callee.name + '()'); + if (isLikelyMochaGlobal(context.getScope(), name)) { + context.report(node, 'Do not pass arrow functions to ' + name + '()'); } } } diff --git a/test/rules/no-mocha-global-arrows.js b/test/rules/no-mocha-global-arrows.js index 4e361e9..ca615d5 100644 --- a/test/rules/no-mocha-global-arrows.js +++ b/test/rules/no-mocha-global-arrows.js @@ -15,7 +15,8 @@ ruleTester.run('no-mocha-global-arrows', rules['no-mocha-global-arrows'], { // In this example, `it` is not a global. code: 'function it () {}; it(() => { console.log("okay") })', parserOptions: { ecmaVersion: 6 } - } + }, + 'it.only()' ], invalid: [ @@ -39,6 +40,11 @@ ruleTester.run('no-mocha-global-arrows', rules['no-mocha-global-arrows'], { code: 'it("should be false", () => { assert(something, false); })', parserOptions: { ecmaVersion: 6 }, errors: [ { message: expectedErrorMessage, column: 1, line: 1 } ] + }, + { + code: 'it.only(() => { assert(something, false); })', + parserOptions: { ecmaVersion: 6 }, + errors: [ { message: 'Do not pass arrow functions to it.only()', column: 1, line: 1 } ] } ]