Skip to content

Commit

Permalink
Merge pull request #195 from lo1tuma/gh-158
Browse files Browse the repository at this point in the history
Fix no-setup-in-describe to work with arrow functions
  • Loading branch information
lo1tuma authored Jul 8, 2019
2 parents d36c149 + 84c68f7 commit dd43791
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/rules/no-setup-in-describe.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ module.exports = function noSetupInDescribe(context) {
}
}

function isParentDescribe(node) {
return astUtils.isDescribe(node.parent, additionalSuiteNames(settings));
}

return {
CallExpression(node) {
const isDescribe = astUtils.isDescribe(node, additionalSuiteNames(settings));
Expand Down Expand Up @@ -86,13 +90,13 @@ module.exports = function noSetupInDescribe(context) {
}
},

ArrowFunctionExpression() {
if (nesting.length) {
ArrowFunctionExpression(node) {
if (nesting.length && !isParentDescribe(node)) {
nesting.push(FUNCTION);
}
},
'ArrowFunctionExpression:exit'() {
if (nesting.length) {
'ArrowFunctionExpression:exit'(node) {
if (nesting.length && !isParentDescribe(node)) {
nesting.pop();
}
}
Expand Down
8 changes: 8 additions & 0 deletions test/rules/no-setup-in-describe.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ ruleTester.run('no-setup-in-describe', rule, {
line: 1,
column: 28
} ]
}, {
code: 'describe("", () => { a(); });',
parserOptions: { ecmaVersion: 2015 },
errors: [ {
message: 'Unexpected function call in describe block.',
line: 1,
column: 22
} ]
}, {
code: 'foo("", function () { a(); });',
settings: {
Expand Down

0 comments on commit dd43791

Please sign in to comment.