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

only check calls where hook is the callee #19

Merged
merged 1 commit into from
Sep 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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