Skip to content

Commit

Permalink
Refactor name logic
Browse files Browse the repository at this point in the history
  • Loading branch information
MattisAbrahamsson committed May 6, 2024
1 parent e974bfe commit be15a89
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/rules/noUsePrefixForNonHook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,27 @@ function arrowFunctionHasImplicitReturnWithUsePrefix(
);
}

function getArrowFunctionName(node: ArrowFunctionExpression) {
if (!("id" in node.parent)) {
return;
}

if (!node.parent.id) {
return;
}

if (!("name" in node.parent.id)) {
return;
}

return node.parent.id.name;
}

export const noUsePrefixForNonHook = ESLintUtils.RuleCreator.withoutDocs({
create(context) {
return {
ArrowFunctionExpression(node) {
const name =
"id" in node.parent &&
node.parent.id &&
"name" in node.parent.id
? node.parent.id?.name
: "";
const name = getArrowFunctionName(node);

if (!name || !hasUsePrefix(name)) {
return;
Expand Down

0 comments on commit be15a89

Please sign in to comment.