Skip to content

Commit

Permalink
Merge pull request #6 from meitner-se/fix/no-use-prefix-allow-call-ex…
Browse files Browse the repository at this point in the history
…pression

[no-use-prefix-for-non-hook]: Fix allow call expression assignment
  • Loading branch information
MattisAbrahamsson authored Aug 5, 2024
2 parents e4a2970 + 1b141d3 commit 046865f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/rules/noUsePrefixForNonHook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,14 @@ export const noUsePrefixForNonHook = ESLintUtils.RuleCreator.withoutDocs({
return;
}

// Check if the variable is assigned a function, we accept functions named as hooks or not, since it's quite common to create a hook with a factory function, such as `createStore` from `zustand`
if (
declaration.init &&
declaration.init.type === "CallExpression"
) {
return;
}

context.report({
node,
messageId: "noUsePrefixForNonHook",
Expand Down
1 change: 1 addition & 0 deletions src/tests/noUsePrefixForNonHook.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ ruleTester.run("noUsePrefixForNonHook", noUsePrefixForNonHook, {
"const user = null;",
"const myVariable = null;",
"const data = useUserData();",
"const useStore = createStore();",
],
invalid: [
{
Expand Down

0 comments on commit 046865f

Please sign in to comment.