Skip to content

Commit

Permalink
Fix: false positives with arrow functions in no-hooks-from-ancestor-m…
Browse files Browse the repository at this point in the history
…odules rule (#275)
  • Loading branch information
bmish committed Nov 29, 2022
1 parent 98572d5 commit abcb81e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rules/no-hooks-from-ancestor-modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ module.exports = {
function getCallbackArg(args) {
// Callback can be either args[1] or args[2]
// https://api.qunitjs.com/QUnit/module/
return args.slice(1, 3).find(arg => arg.type === "FunctionExpression");
return args.slice(1, 3).find(arg => ["FunctionExpression", "ArrowFunctionExpression"].includes(arg.type));
}

function getHooksIdentifierFromParams(params) {
Expand Down
6 changes: 6 additions & 0 deletions tests/lib/rules/no-hooks-from-ancestor-modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ ruleTester.run("no-hooks-from-ancestor-modules", rule, {
QUnit.module("module", function(hooks) { hooks.beforeEach(function() {}); });
`,
`
QUnit.module("module", (hooks) => { hooks.beforeEach(() => {}); });
`,
`
QUnit.module("module", (hooks) => { QUnit.module("module", (hooks) => { hooks.beforeEach(() => {}); }) });
`,
`
QUnit.module("module", function(hooks) { hooks.afterEach(function() {}); });
`,
`
Expand Down

0 comments on commit abcb81e

Please sign in to comment.