1
+ from idom import component
2
+
3
+
4
+ @component
1
5
def HookInIf ():
2
6
if True :
3
7
# error: ROH102 hook 'use_state' used inside if statement
4
8
use_state
5
9
6
10
11
+ @component
7
12
def HookInElif ():
8
13
if False :
9
14
pass
@@ -12,6 +17,7 @@ def HookInElif():
12
17
use_state
13
18
14
19
20
+ @component
15
21
def HookInElse ():
16
22
if False :
17
23
pass
@@ -20,6 +26,7 @@ def HookInElse():
20
26
use_state
21
27
22
28
29
+ @component
23
30
def HookInIfExp ():
24
31
(
25
32
# error: ROH102 hook 'use_state' used inside inline if expression
@@ -29,6 +36,7 @@ def HookInIfExp():
29
36
)
30
37
31
38
39
+ @component
32
40
def HookInElseOfIfExp ():
33
41
(
34
42
None
@@ -39,6 +47,7 @@ def HookInElseOfIfExp():
39
47
)
40
48
41
49
50
+ @component
42
51
def HookInTry ():
43
52
try :
44
53
# error: ROH102 hook 'use_state' used inside try statement
@@ -47,6 +56,7 @@ def HookInTry():
47
56
pass
48
57
49
58
59
+ @component
50
60
def HookInExcept ():
51
61
try :
52
62
raise ValueError ()
@@ -55,6 +65,7 @@ def HookInExcept():
55
65
use_state
56
66
57
67
68
+ @component
58
69
def HookInFinally ():
59
70
try :
60
71
pass
@@ -63,37 +74,45 @@ def HookInFinally():
63
74
use_state
64
75
65
76
77
+ @component
66
78
def HookInForLoop ():
67
79
for i in range (3 ):
68
80
# error: ROH102 hook 'use_state' used inside for loop
69
81
use_state
70
82
71
83
84
+ @component
72
85
def HookInWhileLoop ():
73
86
while True :
74
87
# error: ROH102 hook 'use_state' used inside while loop
75
88
use_state
76
89
77
90
91
+ @component
78
92
def outer_function ():
79
93
# error: ROH100 hook 'use_state' defined as closure in function 'outer_function'
94
+ @component
80
95
def use_state ():
81
96
...
82
97
83
98
99
+ @component
84
100
def generic_function ():
85
101
# error: ROH101 hook 'use_state' used outside component or hook definition
86
102
use_state
87
103
88
104
105
+ @component
89
106
def use_state ():
90
107
use_other
91
108
92
109
110
+ @component
93
111
def Component ():
94
112
use_state
95
113
96
114
115
+ @component
97
116
def use_custom_hook ():
98
117
use_state
99
118
@@ -105,11 +124,13 @@ def use_custom_hook():
105
124
module .use_effect ()
106
125
107
126
127
+ @component
108
128
def not_hook_or_component ():
109
129
# error: ROH101 hook 'use_state' used outside component or hook definition
110
130
use_state
111
131
112
132
133
+ @component
113
134
def CheckEffects ():
114
135
x = 1
115
136
y = 2
@@ -166,34 +187,41 @@ def CheckEffects():
166
187
)
167
188
168
189
@use_effect (args = [x ])
190
+ @component
169
191
def my_effect ():
170
192
x
171
193
172
194
@use_effect (args = [])
195
+ @component
173
196
def my_effect ():
174
197
# error: ROH202 dependency 'x' of function 'my_effect' is not specified in declaration of 'use_effect'
175
198
x
176
199
177
200
@use_effect (args = [])
178
201
@some_other_deco_that_adds_args_to_func_somehow
202
+ @component
179
203
def my_effect (* args , ** kwargs ):
180
204
args
181
205
kwargs
182
206
183
207
@module .use_effect (args = [])
208
+ @component
184
209
def my_effect ():
185
210
# error: ROH202 dependency 'x' of function 'my_effect' is not specified in declaration of 'use_effect'
186
211
x
187
212
188
213
@not_a_decorator_we_care_about
214
+ @component
189
215
def some_func ():
190
216
...
191
217
192
218
@not_a_decorator_we_care_about ()
219
+ @component
193
220
def some_func ():
194
221
...
195
222
196
223
@use_effect
224
+ @component
197
225
def impropper_usage_of_effect_as_decorator ():
198
226
# ignored because bad useage
199
227
x
@@ -210,25 +238,30 @@ def impropper_usage_of_effect_as_decorator():
210
238
)
211
239
212
240
241
+ @component
213
242
def make_component ():
214
243
# nested component definitions are ok.
244
+ @component
215
245
def NestedComponent ():
216
246
use_state
217
247
218
248
219
249
some_global_variable
220
250
221
251
252
+ @component
222
253
def Component ():
223
254
# referencing a global variable is OK
224
255
use_effect (lambda : some_global_variable , [])
225
256
226
257
227
258
if True :
228
259
260
+ @component
229
261
def Component ():
230
262
# this is ok since the conditional is outside the component
231
263
use_state
232
264
265
+ @component
233
266
def use_other ():
234
267
use_state
0 commit comments