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

Commit 81c9ca9

Browse files
committed
fix false possitive early return errors
1 parent 91b93f2 commit 81c9ca9

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

flake8_idom_hooks/rules_of_hooks.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ def visit_FunctionDef(self, node: ast.FunctionDef) -> None:
4242
):
4343
self.generic_visit(node)
4444
else:
45-
with set_current(self, function=node):
45+
with set_current(
46+
self,
47+
function=node,
48+
early_return=None,
49+
):
4650
self.generic_visit(node)
4751

4852
def visit_Call(self, node: ast.Call) -> None:

tests/cases/hook_usage.py

+21
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,24 @@ def example():
190190
return None
191191
# error: ROH103 hook 'use_state' used after an early return
192192
use_state()
193+
194+
195+
@component
196+
def example():
197+
def closure():
198+
# this return is ok since it's not in the same function
199+
return None
200+
201+
# Ok: no early return error
202+
use_state()
203+
204+
205+
@component
206+
def example():
207+
@use_effect
208+
def some_effect():
209+
# this return is ok since it's not in the same function
210+
return None
211+
212+
# Ok: no early return error
213+
use_state()

0 commit comments

Comments
 (0)