Skip to content

Commit a131d0a

Browse files
authored
Fix RenameVariables switching case with scopes (#1472)
1 parent 35a855a commit a131d0a

File tree

5 files changed

+76
-10
lines changed

5 files changed

+76
-10
lines changed

docs/releasenotes/6.7.1.rst

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,8 @@ Robocop is executed on the same major version (6.1.1 for example) without target
2727
Importing external modules in custom rules with the same name as Robocop rules fails (#1467)
2828
--------------------------------------------------------------------------------------------
2929

30-
If custom rule used external module with the same name as one of Robocop rules categories, it failed on import:
30+
If custom rule used external module with the same name as one of Robocop rules categories, it failed on import::
3131

32-
```
33-
from deprecated import deprecated # duplicates with robocop.linter.rules.deprecated.py
34-
```
32+
from deprecated import deprecated # duplicates with robocop.linter.rules.deprecated.py
3533

3634
It was resolved by redesigning our rules importing logic to follow the same behaviour as formatter importer.

docs/releasenotes/6.7.2.rst

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@ Robocop 6.7.2
55
Assertion keywords reported as undefined-argument-value (#1390)
66
---------------------------------------------------------------
77

8-
Assertion keywords used by popular ``AssertionEngine`` library were reported as ``undefined-argument-value`` errors:
8+
Assertion keywords used by popular ``AssertionEngine`` library were reported as ``undefined-argument-value`` errors::
99

10-
```
11-
785 | Get Text ${selector} *= ${alv_check}
12-
| ^^ ARG04
13-
```
10+
785 | Get Text ${selector} *= ${alv_check}
11+
| ^^ ARG04
1412

1513
Robocop should now ignore arguments that match following list: "==", "!=", "<", ">", "<=", ">=", "*=", "^=", "$=", "$".
1614
@@ -19,3 +17,50 @@ SonarQube import issues with diagnostic outside physical locations (#1417)
1917

2018
Fixed issues when reporting SPC10 ``too-many-trailing-blank-lines`` and LEN08 ``line-too-long`` outside physical
2119
locations. Now it should only report start/end lines.
20+
21+
RenameVariables lower-casing VAR variables with global scope (#1425)
22+
--------------------------------------------------------------------
23+
24+
Following code::
25+
26+
*** Keywords ***
27+
Some keyword
28+
&{SOME_DICT} Some keyword that returns a dict
29+
VAR &{SOME_DICT} &{SOME_DICT} scope=TEST
30+
31+
was incorrectly converted to::
32+
33+
*** Keywords ***
34+
Some keyword
35+
&{some_dict} Some keyword that returns a dict
36+
VAR &{some_dict} &{some_dict} scope=TEST
37+
38+
It should now correctly detect new (global) case of variable and convert it to::
39+
40+
*** Keywords ***
41+
Some keyword
42+
&{some_dict} Some keyword that returns a dict
43+
VAR &{SOME_DICT} &{some_dict} scope=TEST
44+
45+
RenameVariables VAR variables stuck forever with local scope (#1425)
46+
--------------------------------------------------------------------
47+
48+
When using VAR with local scope, VAR did not change back to global scope after switching scope again.
49+
50+
Following code::
51+
52+
*** Keywords ***
53+
Some keyword
54+
VAR ${local_variable} scope=local
55+
Log ${local_variable}
56+
VAR ${local_variable} scope=SUITE
57+
Log ${local_variable}
58+
59+
will now be formatted to::
60+
61+
*** Keywords ***
62+
Some keyword
63+
VAR ${local_variable} scope=local
64+
Log ${local_variable}
65+
VAR ${LOCAL_VARIABLE} scope=SUITE
66+
Log ${LOCAL_VARIABLE}

src/robocop/formatter/formatters/RenameVariables.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,10 @@ def visit_Var(self, node): # noqa: N802
458458
if variable:
459459
if self._is_var_scope_local(node):
460460
self.variables_scope.add_local(variable.value)
461-
variable.value = self.rename_value(variable.value, variable_case=VariableCase.AUTO, is_var=False)
461+
variable.value = self.rename_value(variable.value, variable_case=VariableCase.LOWER, is_var=False)
462+
else:
463+
self.variables_scope.change_scope_from_local_to_global(variable.value)
464+
variable.value = self.rename_value(variable.value, variable_case=VariableCase.UPPER, is_var=False)
462465
return node
463466

464467
@staticmethod

tests/formatter/formatters/RenameVariables/expected/VAR_syntax.robot

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ Change scope
2121
VAR ${SUITE} value scope=SUITE
2222
VAR ${GLOBAL} value scope=GLOBAL
2323
VAR ${TEST} value scope=TEST
24+
&{some_dict} Some Keyword With Local Return
25+
VAR &{SOME_DICT} &{some_dict} scope=TEST
2426
VAR ${TASK} value scope=TASK
2527
VAR ${local_default} value scope=local
2628

@@ -41,6 +43,14 @@ Change scope
4143
VAR ${VARIABLE} value scope=${dynamic_scope}
4244
Log ${VARIABLE}
4345

46+
# change scope again
47+
Log ${TEST}
48+
VAR ${test} value scope=local
49+
Log ${test}
50+
VAR ${TEST} value scope=TEST
51+
Log ${TEST}
52+
VAR &{some_dict} &{SOME_DICT}
53+
4454
List
4555
# Creates a list with three items.
4656
VAR @{list} a b c

tests/formatter/formatters/RenameVariables/source/VAR_syntax.robot

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ Change scope
2121
VAR ${suite} value scope=SUITE
2222
VAR ${global} value scope=GLOBAL
2323
VAR ${test} value scope=TEST
24+
&{some_dict} Some Keyword With Local Return
25+
VAR &{some_dict} &{some_dict} scope=TEST
2426
VAR ${task} value scope=TASK
2527
VAR ${local_default} value scope=local
2628

@@ -41,6 +43,14 @@ Change scope
4143
VAR ${variable} value scope=${dynamic_scope}
4244
Log ${variable}
4345

46+
# change scope again
47+
Log ${TEST}
48+
VAR ${test} value scope=local
49+
Log ${test}
50+
VAR ${TEST} value scope=TEST
51+
Log ${TEST}
52+
VAR &{some_dict} &{SOME_DICT}
53+
4454
List
4555
# Creates a list with three items.
4656
VAR @{list} a b c

0 commit comments

Comments
 (0)