Skip to content

Commit 1d8428a

Browse files
committed
feat: Variable type conversion - support non-local-variables-should-be-uppercase
1 parent 9a0f525 commit 1d8428a

File tree

4 files changed

+100
-0
lines changed

4 files changed

+100
-0
lines changed

src/robocop/linter/rules/naming.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,6 +1102,8 @@ def check_non_local_variable(self, variable_name: str, node, token) -> None:
11021102
normalized_var_name = utils.remove_nested_variables(variable_name)
11031103
if not normalized_var_name:
11041104
return
1105+
if TYPE_SUPPORTED:
1106+
normalized_var_name, *_ = normalized_var_name.split(": ", 1)
11051107
# a variable as a keyword argument can contain lowercase nested variable
11061108
# because the actual value of it may be uppercase
11071109
if not normalized_var_name.isupper():
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
var_typing.robot:3:24 VAR07 Non local variable is not uppercase
2+
|
3+
1 | *** Test Cases ***
4+
2 | Set report
5+
3 | Set Task Variable ${my_var: int} 0
6+
| ^^^^^^^^^^^^^^ VAR07
7+
4 | Set Suite Variable ${my var: list[str]} 0
8+
5 | Set Test Variable ${My Var: Enum} 0
9+
|
10+
11+
var_typing.robot:4:25 VAR07 Non local variable is not uppercase
12+
|
13+
2 | Set report
14+
3 | Set Task Variable ${my_var: int} 0
15+
4 | Set Suite Variable ${my var: list[str]} 0
16+
| ^^^^^^^^^^^^^^^^^^^^ VAR07
17+
5 | Set Test Variable ${My Var: Enum} 0
18+
6 | Set Global Variable ${My_Var: str} 0
19+
|
20+
21+
var_typing.robot:5:24 VAR07 Non local variable is not uppercase
22+
|
23+
3 | Set Task Variable ${my_var: int} 0
24+
4 | Set Suite Variable ${my var: list[str]} 0
25+
5 | Set Test Variable ${My Var: Enum} 0
26+
| ^^^^^^^^^^^^^^^ VAR07
27+
6 | Set Global Variable ${My_Var: str} 0
28+
|
29+
30+
var_typing.robot:6:26 VAR07 Non local variable is not uppercase
31+
|
32+
4 | Set Suite Variable ${my var: list[str]} 0
33+
5 | Set Test Variable ${My Var: Enum} 0
34+
6 | Set Global Variable ${My_Var: str} 0
35+
| ^^^^^^^^^^^^^^ VAR07
36+
|
37+
38+
var_typing.robot:15:12 VAR07 Non local variable is not uppercase
39+
|
40+
13 |
41+
14 | VAR report
42+
15 | VAR ${suite: int} value scope=SUITE
43+
| ^^^^^^^^^^^^^ VAR07
44+
16 | VAR ${global: list[str]} value scope=GLOBAL
45+
17 | VAR ${test: Enum} value scope=TEST
46+
|
47+
48+
var_typing.robot:16:12 VAR07 Non local variable is not uppercase
49+
|
50+
14 | VAR report
51+
15 | VAR ${suite: int} value scope=SUITE
52+
16 | VAR ${global: list[str]} value scope=GLOBAL
53+
| ^^^^^^^^^^^^^^^^^^^^ VAR07
54+
17 | VAR ${test: Enum} value scope=TEST
55+
18 | VAR ${task: str} value scope=TASK
56+
|
57+
58+
var_typing.robot:18:12 VAR07 Non local variable is not uppercase
59+
|
60+
16 | VAR ${global: list[str]} value scope=GLOBAL
61+
17 | VAR ${test: Enum} value scope=TEST
62+
18 | VAR ${task: str} value scope=TASK
63+
| ^^^^^^^^^^^^ VAR07
64+
|
65+
66+
Found 7 issues.

tests/linter/rules/variables/non_local_variables_should_be_uppercase/test_rule.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,11 @@ def test_extended(self):
1010

1111
def test_var(self):
1212
self.check_rule(src_files=["VAR_syntax.robot"], expected_file="expected_output_var.txt", test_on_version=">=7")
13+
14+
def test_var_typing(self):
15+
self.check_rule(
16+
src_files=["var_typing.robot"],
17+
expected_file="expected_extended_var_typing.txt",
18+
output_format="extended",
19+
test_on_version=">=7.3",
20+
)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
*** Test Cases ***
2+
Set report
3+
Set Task Variable ${my_var: int} 0
4+
Set Suite Variable ${my var: list[str]} 0
5+
Set Test Variable ${My Var: Enum} 0
6+
Set Global Variable ${My_Var: str} 0
7+
8+
Set ignore
9+
Set Task Variable ${MY_VAR: int} 1
10+
Set Suite Variable ${MY VAR: list[str]} 1
11+
Set Test Variable ${MY_VAR: Enum} 1
12+
Set Global Variable ${MY VAR: str} 1
13+
14+
VAR report
15+
VAR ${suite: int} value scope=SUITE
16+
VAR ${global: list[str]} value scope=GLOBAL
17+
VAR ${test: Enum} value scope=TEST
18+
VAR ${task: str} value scope=TASK
19+
20+
VAR ignore
21+
VAR ${SUITE: int} value scope=SUITE
22+
VAR ${GLOBAL: list[str]} value scope=GLOBAL
23+
VAR ${TEST: Enum} value scope=TEST
24+
VAR ${TASK: str} value scope=TASK

0 commit comments

Comments
 (0)