Skip to content

Commit

Permalink
Update: no-hooks-from-ancestor-modules works with arrow module callba…
Browse files Browse the repository at this point in the history
…cks (#267)

Fixes #246
  • Loading branch information
platinumazure committed Nov 20, 2022
1 parent bdb2254 commit f02b60f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
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 @@ -47,7 +47,7 @@ module.exports = {
callExpressionNode.parent.parent &&
callExpressionNode.parent.parent.type === "BlockStatement" &&
callExpressionNode.parent.parent.parent &&
callExpressionNode.parent.parent.parent.type === "FunctionExpression" &&
["FunctionExpression", "ArrowFunctionExpression"].includes(callExpressionNode.parent.parent.parent.type) &&
callExpressionNode.parent.parent.parent.parent &&
callExpressionNode.parent.parent.parent.parent.type === "CallExpression" &&
utils.isModule(callExpressionNode.parent.parent.parent.parent.callee);
Expand Down
34 changes: 33 additions & 1 deletion tests/lib/rules/no-hooks-from-ancestor-modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function createError({ invokedMethodName, usedHooksIdentifierName }) {
// Tests
//------------------------------------------------------------------------------

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

valid: [
Expand Down Expand Up @@ -244,6 +244,38 @@ ruleTester.run("no-hooks-from-ancestor-modules", rule, {
]
},

// https://github.com/platinumazure/eslint-plugin-qunit/issues/246
{
code: `
QUnit.module("module-a", function (hooks) {
QUnit.module("module-b", () => {
hooks.beforeEach(function () {});
});
});
`,
errors: [
createError({
invokedMethodName: "beforeEach",
usedHooksIdentifierName: "hooks"
})
]
},
{
code: `
QUnit.module("module-a", (hooks) => {
QUnit.module("module-b", () => {
hooks.beforeEach(() => {});
});
});
`,
errors: [
createError({
invokedMethodName: "beforeEach",
usedHooksIdentifierName: "hooks"
})
]
},

{
// TypeScript: module callback is adding a type to `this`
code: `
Expand Down

0 comments on commit f02b60f

Please sign in to comment.