Skip to content

Commit f02b60f

Browse files
authoredNov 20, 2022
Update: no-hooks-from-ancestor-modules works with arrow module callbacks (#267)
Fixes #246
1 parent bdb2254 commit f02b60f

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed
 

‎lib/rules/no-hooks-from-ancestor-modules.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ module.exports = {
4747
callExpressionNode.parent.parent &&
4848
callExpressionNode.parent.parent.type === "BlockStatement" &&
4949
callExpressionNode.parent.parent.parent &&
50-
callExpressionNode.parent.parent.parent.type === "FunctionExpression" &&
50+
["FunctionExpression", "ArrowFunctionExpression"].includes(callExpressionNode.parent.parent.parent.type) &&
5151
callExpressionNode.parent.parent.parent.parent &&
5252
callExpressionNode.parent.parent.parent.parent.type === "CallExpression" &&
5353
utils.isModule(callExpressionNode.parent.parent.parent.parent.callee);

‎tests/lib/rules/no-hooks-from-ancestor-modules.js

+33-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function createError({ invokedMethodName, usedHooksIdentifierName }) {
3030
// Tests
3131
//------------------------------------------------------------------------------
3232

33-
const ruleTester = new RuleTester();
33+
const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: "latest" } });
3434
ruleTester.run("no-hooks-from-ancestor-modules", rule, {
3535

3636
valid: [
@@ -244,6 +244,38 @@ ruleTester.run("no-hooks-from-ancestor-modules", rule, {
244244
]
245245
},
246246

247+
// https://github.com/platinumazure/eslint-plugin-qunit/issues/246
248+
{
249+
code: `
250+
QUnit.module("module-a", function (hooks) {
251+
QUnit.module("module-b", () => {
252+
hooks.beforeEach(function () {});
253+
});
254+
});
255+
`,
256+
errors: [
257+
createError({
258+
invokedMethodName: "beforeEach",
259+
usedHooksIdentifierName: "hooks"
260+
})
261+
]
262+
},
263+
{
264+
code: `
265+
QUnit.module("module-a", (hooks) => {
266+
QUnit.module("module-b", () => {
267+
hooks.beforeEach(() => {});
268+
});
269+
});
270+
`,
271+
errors: [
272+
createError({
273+
invokedMethodName: "beforeEach",
274+
usedHooksIdentifierName: "hooks"
275+
})
276+
]
277+
},
278+
247279
{
248280
// TypeScript: module callback is adding a type to `this`
249281
code: `

0 commit comments

Comments
 (0)
Please sign in to comment.