Skip to content

Commit

Permalink
Merge pull request #239 from lo1tuma/fix-top-level
Browse files Browse the repository at this point in the history
Fix max-top-level-suites to ignore generated suites
  • Loading branch information
lo1tuma authored Feb 19, 2020
2 parents 1c3a545 + 2633908 commit a18680d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
11 changes: 2 additions & 9 deletions lib/rules/max-top-level-suites.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ module.exports = {
]
},
create(context) {
const stack = [];
const topLevelDescribes = [];
const options = context.options[0] || {};
const settings = context.settings;
Expand All @@ -41,17 +40,11 @@ module.exports = {
return {
CallExpression(node) {
if (astUtil.isDescribe(node, additionalSuiteNames(settings))) {
stack.push(node);
}
},
const scope = context.getScope();

'CallExpression:exit'(node) {
if (astUtil.isDescribe(node, additionalSuiteNames(settings))) {
if (stack.length === 1) {
if (scope.upper === null) {
topLevelDescribes.push(node);
}

stack.pop(node);
}
},

Expand Down
3 changes: 2 additions & 1 deletion test/rules/max-top-level-suites.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ ruleTester.run('max-top-level-suites', rules['max-top-level-suites'], {
}
}
},
'someOtherFunction();'
'someOtherFunction();',
'describe("top", function () {}); function foo() { describe("not necessarily top", function () {}); }'
],

invalid: [
Expand Down

0 comments on commit a18680d

Please sign in to comment.