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

Commit 6e05ad3

Browse files
committed
change error code name
1 parent 1ebb7c0 commit 6e05ad3

9 files changed

+46
-44
lines changed

README.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pip install -e .
2020
Run the tests
2121

2222
```bash
23-
tox
23+
nox -s test
2424
```
2525

2626
# Errors
@@ -31,34 +31,34 @@ tox
3131
<th>Message</th>
3232
</tr>
3333
<tr>
34-
<td>ROH100</td>
34+
<td>REACTPY100</td>
3535
<td>Hook is defined as a closure</td>
3636
</tr>
3737
<tr>
38-
<td>ROH101</td>
38+
<td>REACTPY101</td>
3939
<td>Hook was used outside component or hook definition</td>
4040
</tr>
4141
<tr>
42-
<td>ROH102</td>
42+
<td>REACTPY102</td>
4343
<td>Hook was used inside a conditional or loop statement</td>
4444
</tr>
4545
<tr>
46-
<td>ROH103</td>
46+
<td>REACTPY103</td>
4747
<td>Hook was used after an early return</td>
4848
</tr>
4949
<tr>
50-
<td>ROH200</td>
50+
<td>REACTPY200</td>
5151
<td>
5252
A hook's dependency is not destructured - dependencies should be refered to
5353
directly, not via an attribute or key of an object
5454
</td>
5555
</tr>
5656
<tr>
57-
<td>ROH201</td>
57+
<td>REACTPY201</td>
5858
<td>Hook dependency args should be a literal list, tuple or None</td>
5959
</tr>
6060
<tr>
61-
<td>ROH202</td>
61+
<td>REACTPY202</td>
6262
<td>
6363
Hook dependency is not specified
6464
</td>
@@ -81,7 +81,7 @@ example, `exhaustive_hook_deps` would become `--exhaustive-hook-deps`.
8181
<td><code>exhaustive_hook_deps</code></td>
8282
<td>Boolean</td>
8383
<td><code>False</code></td>
84-
<td>Enable <code>ROH2**</code> errors (recommended)</td>
84+
<td>Enable <code>REACTPY2**</code> errors (recommended)</td>
8585
</tr>
8686
<tr>
8787
<td><code>component_decorator_pattern</code></td>

reactpy_flake8/common.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ def __init__(
2727
self._component_decorator_pattern = re.compile(component_decorator_pattern)
2828

2929
def add_error(self, error_code: int, node: ast.AST, message: str) -> None:
30-
self.errors.append((node.lineno, node.col_offset, f"ROH{error_code} {message}"))
30+
self.errors.append(
31+
(node.lineno, node.col_offset, f"REACTPY{error_code} {message}")
32+
)
3133

3234
def is_hook_def(self, node: ast.FunctionDef) -> bool:
3335
return self.is_hook_name(node.name)

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
package = {
1919
"name": name,
2020
"packages": setuptools.find_packages(exclude=["tests*"]),
21-
"entry_points": {"flake8.extension": ["ROH=reactpy_flake8:plugin"]},
21+
"entry_points": {"flake8.extension": ["REACTPY=reactpy_flake8:plugin"]},
2222
"python_requires": ">=3.6",
2323
"description": "Flake8 plugin to enforce the rules of hooks for ReactPy",
2424
"author": "Ryan Morshead",
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
@component
22
def check_normal_pattern():
33
if True:
4-
# error: ROH102 hook 'use_state' used inside if statement
4+
# error: REACTPY102 hook 'use_state' used inside if statement
55
use_state()
66

77

88
@custom_component
99
def check_custom_pattern():
1010
if True:
11-
# error: ROH102 hook 'use_state' used inside if statement
11+
# error: REACTPY102 hook 'use_state' used inside if statement
1212
use_state()

tests/cases/custom_hook_function_pattern.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ def check():
33
if True:
44
# this get's ignored because of custom pattern
55
use_ignore_this()
6-
# error: ROH102 hook 'use_state' used inside if statement
6+
# error: REACTPY102 hook 'use_state' used inside if statement
77
use_state()

tests/cases/exhaustive_deps.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# error: ROH101 hook 'use_effect' used outside component or hook definition
1+
# error: REACTPY101 hook 'use_effect' used outside component or hook definition
22
use_effect(lambda: x) # no need to check deps outside component/hook
33

44

@@ -12,7 +12,7 @@ def check_effects():
1212

1313
use_effect(
1414
lambda: (
15-
# error: ROH202 dependency 'x' of function 'lambda' is not specified in declaration of 'use_effect'
15+
# error: REACTPY202 dependency 'x' of function 'lambda' is not specified in declaration of 'use_effect'
1616
x
1717
+ y
1818
),
@@ -21,49 +21,49 @@ def check_effects():
2121

2222
use_effect(
2323
lambda: (
24-
# error: ROH202 dependency 'x' of function 'lambda' is not specified in declaration of 'use_effect'
24+
# error: REACTPY202 dependency 'x' of function 'lambda' is not specified in declaration of 'use_effect'
2525
x
2626
)
2727
)
2828

2929
use_effect(
3030
lambda: (
31-
# error: ROH202 dependency 'x' of function 'lambda' is not specified in declaration of 'use_effect'
31+
# error: REACTPY202 dependency 'x' of function 'lambda' is not specified in declaration of 'use_effect'
3232
x.y
3333
),
3434
[
35-
# error: ROH200 dependency arg of 'use_effect' is not destructured - dependencies should be refered to directly, not via an attribute or key of an object
35+
# error: REACTPY200 dependency arg of 'use_effect' is not destructured - dependencies should be refered to directly, not via an attribute or key of an object
3636
x.y
3737
],
3838
)
3939

4040
module.use_effect(
4141
lambda: (
42-
# error: ROH202 dependency 'x' of function 'lambda' is not specified in declaration of 'use_effect'
42+
# error: REACTPY202 dependency 'x' of function 'lambda' is not specified in declaration of 'use_effect'
4343
x
4444
),
4545
[],
4646
)
4747

4848
module.submodule.use_effect(
4949
lambda: (
50-
# error: ROH202 dependency 'x' of function 'lambda' is not specified in declaration of 'use_effect'
50+
# error: REACTPY202 dependency 'x' of function 'lambda' is not specified in declaration of 'use_effect'
5151
x
5252
),
5353
[],
5454
)
5555

5656
use_effect(
5757
lambda: (
58-
# error: ROH202 dependency 'x' of function 'lambda' is not specified in declaration of 'use_effect'
58+
# error: REACTPY202 dependency 'x' of function 'lambda' is not specified in declaration of 'use_effect'
5959
x
6060
),
6161
args=[],
6262
)
6363

6464
use_effect(
6565
function=lambda: (
66-
# error: ROH202 dependency 'x' of function 'lambda' is not specified in declaration of 'use_effect'
66+
# error: REACTPY202 dependency 'x' of function 'lambda' is not specified in declaration of 'use_effect'
6767
x
6868
),
6969
args=[],
@@ -75,7 +75,7 @@ def my_effect():
7575

7676
@use_effect(args=[])
7777
def my_effect():
78-
# error: ROH202 dependency 'x' of function 'my_effect' is not specified in declaration of 'use_effect'
78+
# error: REACTPY202 dependency 'x' of function 'my_effect' is not specified in declaration of 'use_effect'
7979
x
8080

8181
@use_effect(args=[])
@@ -86,7 +86,7 @@ def my_effect(*args, **kwargs):
8686

8787
@module.use_effect(args=[])
8888
def my_effect():
89-
# error: ROH202 dependency 'x' of function 'my_effect' is not specified in declaration of 'use_effect'
89+
# error: REACTPY202 dependency 'x' of function 'my_effect' is not specified in declaration of 'use_effect'
9090
x
9191

9292
@not_a_decorator_we_care_about
@@ -104,7 +104,7 @@ def impropper_usage_of_effect_as_decorator():
104104

105105
use_effect(
106106
lambda: None,
107-
# error: ROH201 dependency args of 'use_effect' should be a literal list, tuple, or None - not expression type 'Name'
107+
# error: REACTPY201 dependency args of 'use_effect' should be a literal list, tuple, or None - not expression type 'Name'
108108
not_a_list_or_tuple,
109109
)
110110

tests/cases/hook_usage.py

+16-16
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def HookInIfNoCall():
1414
@component
1515
def HookInIf():
1616
if True:
17-
# error: ROH102 hook 'use_state' used inside if statement
17+
# error: REACTPY102 hook 'use_state' used inside if statement
1818
use_state()
1919

2020

@@ -24,7 +24,7 @@ def HookInIfInExpression():
2424
(
2525
None
2626
or
27-
# error: ROH102 hook 'use_state' used inside if statement
27+
# error: REACTPY102 hook 'use_state' used inside if statement
2828
use_state
2929
)()
3030

@@ -34,7 +34,7 @@ def HookInElif():
3434
if False:
3535
pass
3636
elif True:
37-
# error: ROH102 hook 'use_state' used inside if statement
37+
# error: REACTPY102 hook 'use_state' used inside if statement
3838
use_state()
3939

4040

@@ -43,14 +43,14 @@ def HookInElse():
4343
if False:
4444
pass
4545
else:
46-
# error: ROH102 hook 'use_state' used inside if statement
46+
# error: REACTPY102 hook 'use_state' used inside if statement
4747
use_state()
4848

4949

5050
@component
5151
def HookInIfExp():
5252
(
53-
# error: ROH102 hook 'use_state' used inside inline if expression
53+
# error: REACTPY102 hook 'use_state' used inside inline if expression
5454
use_state()
5555
if True
5656
else None
@@ -63,15 +63,15 @@ def HookInElseOfIfExp():
6363
None
6464
if True
6565
else
66-
# error: ROH102 hook 'use_state' used inside inline if expression
66+
# error: REACTPY102 hook 'use_state' used inside inline if expression
6767
use_state()
6868
)
6969

7070

7171
@component
7272
def HookInTry():
7373
try:
74-
# error: ROH102 hook 'use_state' used inside try statement
74+
# error: REACTPY102 hook 'use_state' used inside try statement
7575
use_state()
7676
except:
7777
pass
@@ -82,7 +82,7 @@ def HookInExcept():
8282
try:
8383
raise ValueError()
8484
except:
85-
# error: ROH102 hook 'use_state' used inside try statement
85+
# error: REACTPY102 hook 'use_state' used inside try statement
8686
use_state()
8787

8888

@@ -91,32 +91,32 @@ def HookInFinally():
9191
try:
9292
pass
9393
finally:
94-
# error: ROH102 hook 'use_state' used inside try statement
94+
# error: REACTPY102 hook 'use_state' used inside try statement
9595
use_state()
9696

9797

9898
@component
9999
def HookInForLoop():
100100
for i in range(3):
101-
# error: ROH102 hook 'use_state' used inside for loop
101+
# error: REACTPY102 hook 'use_state' used inside for loop
102102
use_state()
103103

104104

105105
@component
106106
def HookInWhileLoop():
107107
while True:
108-
# error: ROH102 hook 'use_state' used inside while loop
108+
# error: REACTPY102 hook 'use_state' used inside while loop
109109
use_state()
110110

111111

112112
def outer_function():
113-
# error: ROH100 hook 'use_state' defined as closure in function 'outer_function'
113+
# error: REACTPY100 hook 'use_state' defined as closure in function 'outer_function'
114114
def use_state():
115115
...
116116

117117

118118
def generic_function():
119-
# error: ROH101 hook 'use_state' used outside component or hook definition
119+
# error: REACTPY101 hook 'use_state' used outside component or hook definition
120120
use_state()
121121

122122

@@ -146,12 +146,12 @@ def use_custom_hook():
146146
# ok since use state is not called
147147
module.use_effect
148148

149-
# error: ROH101 hook 'use_effect' used outside component or hook definition
149+
# error: REACTPY101 hook 'use_effect' used outside component or hook definition
150150
module.use_effect()
151151

152152

153153
def not_hook_or_component():
154-
# error: ROH101 hook 'use_state' used outside component or hook definition
154+
# error: REACTPY101 hook 'use_state' used outside component or hook definition
155155
use_state()
156156

157157

@@ -188,7 +188,7 @@ def use_other():
188188
def example():
189189
if True:
190190
return None
191-
# error: ROH103 hook 'use_state' used after an early return on line 190
191+
# error: REACTPY103 hook 'use_state' used after an early return on line 190
192192
use_state()
193193

194194

tests/cases/match_statement.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
def example():
33
match something:
44
case int:
5-
# error: ROH102 hook 'use_state' used inside match statement
5+
# error: REACTPY102 hook 'use_state' used inside match statement
66
use_state()

tests/cases/no_exhaustive_deps.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# confirm that we're still checking for other errors
22
def generic_function():
3-
# error: ROH101 hook 'use_state' used outside component or hook definition
3+
# error: REACTPY101 hook 'use_state' used outside component or hook definition
44
use_state()
55

66

0 commit comments

Comments
 (0)