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

Commit 78c5026

Browse files
Archmongerrmorshea
authored andcommitted
fix tests
1 parent 08efc69 commit 78c5026

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

flake8_idom_hooks/utils.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,14 @@ def is_hook_def(node: ast.FunctionDef) -> bool:
2929

3030
def is_component_def(node: ast.FunctionDef) -> bool:
3131
return any(
32-
decorator.value.id == "idom" and decorator.attr == "component"
33-
for decorator in node.decorator_list
32+
is_idom_component_decorator(decorator) for decorator in node.decorator_list
33+
)
34+
35+
36+
def is_idom_component_decorator(node) -> bool:
37+
return getattr(node, "id", None) == "component" or (
38+
getattr(getattr(node, "value", None), "id", None) == "idom"
39+
and getattr(node, "attr", None) == "component"
3440
)
3541

3642

tests/hook_usage_test_cases.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import idom
12
from idom import component
23

34

@@ -88,16 +89,14 @@ def HookInWhileLoop():
8889
use_state
8990

9091

91-
@component
9292
def outer_function():
9393
# error: ROH100 hook 'use_state' defined as closure in function 'outer_function'
94-
@component
9594
def use_state():
9695
...
9796

9897

99-
@component
10098
def generic_function():
99+
101100
# error: ROH101 hook 'use_state' used outside component or hook definition
102101
use_state
103102

@@ -112,6 +111,11 @@ def Component():
112111
use_state
113112

114113

114+
@idom.component
115+
def IdomLongImportComponent():
116+
use_state
117+
118+
115119
@component
116120
def use_custom_hook():
117121
use_state
@@ -124,7 +128,6 @@ def use_custom_hook():
124128
module.use_effect()
125129

126130

127-
@component
128131
def not_hook_or_component():
129132
# error: ROH101 hook 'use_state' used outside component or hook definition
130133
use_state
@@ -187,41 +190,34 @@ def CheckEffects():
187190
)
188191

189192
@use_effect(args=[x])
190-
@component
191193
def my_effect():
192194
x
193195

194196
@use_effect(args=[])
195-
@component
196197
def my_effect():
197198
# error: ROH202 dependency 'x' of function 'my_effect' is not specified in declaration of 'use_effect'
198199
x
199200

200201
@use_effect(args=[])
201202
@some_other_deco_that_adds_args_to_func_somehow
202-
@component
203203
def my_effect(*args, **kwargs):
204204
args
205205
kwargs
206206

207207
@module.use_effect(args=[])
208-
@component
209208
def my_effect():
210209
# error: ROH202 dependency 'x' of function 'my_effect' is not specified in declaration of 'use_effect'
211210
x
212211

213212
@not_a_decorator_we_care_about
214-
@component
215213
def some_func():
216214
...
217215

218216
@not_a_decorator_we_care_about()
219-
@component
220217
def some_func():
221218
...
222219

223220
@use_effect
224-
@component
225221
def impropper_usage_of_effect_as_decorator():
226222
# ignored because bad useage
227223
x

0 commit comments

Comments
 (0)