Skip to content
This repository has been archived by the owner on Jan 15, 2025. It is now read-only.

Commit

Permalink
only check calls where hook is the callee
Browse files Browse the repository at this point in the history
  • Loading branch information
rmorshea committed Sep 18, 2022
1 parent f16aeaa commit 91b93f2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 6 additions & 2 deletions flake8_idom_hooks/rules_of_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,14 @@ def visit_FunctionDef(self, node: ast.FunctionDef) -> None:

def visit_Call(self, node: ast.Call) -> None:
with set_current(self, call=node):
self.generic_visit(node)
self.visit(node.func)
for a in node.args:
self.visit(a)
for kw in node.keywords:
self.visit(kw)

def _visit_hook_usage(self, node: ast.Name | ast.Attribute) -> None:
if self._current_call:
if self._current_call is not None:
self._check_if_propper_hook_usage(node)

visit_Attribute = _visit_hook_usage
Expand Down
2 changes: 2 additions & 0 deletions tests/cases/hook_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ def HookInIfNoCall():
if True:
# Ok, hook was not called
use_state
# Also ok, hook itself was not called
func(use_state)


@component
Expand Down

0 comments on commit 91b93f2

Please sign in to comment.