Skip to content

Commit

Permalink
Fix for it.only
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Melnikow committed Jul 13, 2016
1 parent b81be5b commit b18e8ba
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
16 changes: 12 additions & 4 deletions lib/rules/no-mocha-global-arrows.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 + '()');
}
}
}
Expand Down
8 changes: 7 additions & 1 deletion test/rules/no-mocha-global-arrows.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand All @@ -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 } ]
}
]

Expand Down

0 comments on commit b18e8ba

Please sign in to comment.