Skip to content

Commit d6e69f0

Browse files
bhirszmnojek
andauthored
Rename variables (#502)
* Add RenameVariables transformer for renaming and normalizing variable names Co-authored-by: Mateusz Nojek <matnojek@gmail.com>
1 parent e2d1e56 commit d6e69f0

24 files changed

+1965
-87
lines changed

docs/releasenotes/4.0.0.rst

Lines changed: 150 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ Major release which contains multiple improvements for external transformers. Th
55
changes, including removing ``section`` option from ``NormalizeSeparators`` (replaced with ``skip_sections``). We have
66
also added following new transformers:
77

8-
- RemoveEmptyValues
8+
- RenameVariables
9+
- NormalizeComments
10+
- ReplaceEmptyValues
911
- GenerateDocumentation
1012

1113
You can install the latest available version by running::
@@ -16,6 +18,152 @@ or to install exactly this version::
1618

1719
pip install robotframework-tidy==4.0.0
1820

21+
New transformer RenameVariables (#354)
22+
---------------------------------------
23+
24+
Transformer that renames and normalizes variable names.
25+
26+
Following conventions are applied:
27+
28+
- variable case depends on the variable scope (lowercase for local variables and uppercase for non-local variables)
29+
- leading and trailing whitespace is stripped
30+
- more than 2 consecutive whitespace in name is replaced by 1
31+
- whitespace is replaced by _
32+
- camelCase is converted to snake_case
33+
34+
Conventions can be configured or switched off using parameters - read more in the documentation.
35+
36+
Following code::
37+
38+
*** Settings ***
39+
Suite Setup ${keyword}
40+
41+
*** Variables ***
42+
${global} String with {other global}
43+
44+
*** Test Cases ***
45+
Test
46+
${local} Set Variable variable
47+
Log ${local}
48+
Log ${global}
49+
Log ${local['item']}
50+
51+
*** Keywords ***
52+
Keyword
53+
[Arguments] ${ARG}
54+
Log ${arg}
55+
56+
Keyword With ${EMBEDDED}
57+
Log ${emb eded}
58+
59+
will be transformed to::
60+
61+
*** Settings ***
62+
Suite Setup ${KEYWORD}
63+
64+
*** Variables ***
65+
${GLOBAL} String with {OTHER_GLOBAL}
66+
67+
*** Test Cases ***
68+
Test
69+
${local} Set Variable variable
70+
Log ${local}
71+
Log ${GLOBAL}
72+
Log ${local['item']}
73+
74+
*** Keywords ***
75+
Keyword
76+
[Arguments] ${arg}
77+
Log ${arg}
78+
79+
Keyword With ${embedded}
80+
Log ${emb_eded}
81+
82+
New transformer ReplaceEmptyValues (#474)
83+
------------------------------------------
84+
85+
This new, enabled by default transformer replaces empty values with ``${EMPTY}`` variable.
86+
87+
Empty variables, lists or elements in the list can be defined in the following way::
88+
89+
*** Variables ***
90+
${EMPTY_VALUE}
91+
@{EMPTY_LIST}
92+
&{EMPTY_DICT}
93+
@{LIST_WITH_EMPTY}
94+
... value
95+
...
96+
... value3
97+
98+
To be more explicit, this transformer replace such values with ``${EMPTY}`` variables::
99+
100+
*** Variables ***
101+
${EMPTY_VALUE} ${EMPTY}
102+
@{EMPTY_LIST} @{EMPTY}
103+
&{EMPTY_DICT} &{EMPTY}
104+
@{LIST_WITH_EMPTY}
105+
... value
106+
... ${EMPTY}
107+
... value3
108+
109+
New transformer NormalizeComments (#290)
110+
-----------------------------------------
111+
112+
``NormalizeComments`` handles comments formatting. For now, it only focuses on fixing ``missing-space-after-comment``
113+
rule violations from the Robocop::
114+
115+
*** Settings ***
116+
#linecomment
117+
### header
118+
119+
120+
*** Keywords ***
121+
Keyword
122+
Step #comment
123+
124+
will be transformed to::
125+
126+
*** Settings ***
127+
# linecomment
128+
### header
129+
130+
131+
*** Keywords ***
132+
Keyword
133+
Step # comment
134+
```
135+
136+
New transformer GenerateDocumentation (#311)
137+
--------------------------------------------
138+
139+
Transformer that allows you to generate keyword documentation stubs based on the keyword data such as
140+
name, arguments or returned values. It uses Jinja templating internally and allows to define your own
141+
documentation templates. With default template (Google docstring) and following code::
142+
143+
*** Keywords ***
144+
Keyword
145+
[Arguments] ${arg}
146+
${var} ${var2} Step
147+
RETURN ${var} ${var2}
148+
149+
it will generate::
150+
151+
*** Keywords ***
152+
Keyword
153+
[Documentation]
154+
...
155+
... Arguments:
156+
... ${arg}:
157+
...
158+
... Returns:
159+
... ${var}
160+
... ${var2}
161+
[Arguments] ${arg}
162+
${var} ${var2} Step
163+
RETURN ${var} ${var2}
164+
165+
Read the transformer documentation for more details on configuring your own custom template.
166+
19167
Rerun the transformation in place
20168
----------------------------------
21169

@@ -101,6 +249,7 @@ Currently supported in::
101249
NormalizeNewLines
102250
NormalizeSectionHeaderName
103251
NormalizeSeparators
252+
RenameVariables
104253
ReplaceEmptyValues
105254
SplitTooLongLine
106255

@@ -122,91 +271,6 @@ Is now equivalent of::
122271

123272
> robotidy -c NormalizeSeparators:skip_sections=keywords
124273

125-
New transformer ReplaceEmptyValues (#474)
126-
------------------------------------------
127-
128-
This new, enabled by default transformer replaces empty values with ``${EMPTY}`` variable.
129-
130-
Empty variables, lists or elements in the list can be defined in the following way::
131-
132-
*** Variables ***
133-
${EMPTY_VALUE}
134-
@{EMPTY_LIST}
135-
&{EMPTY_DICT}
136-
@{LIST_WITH_EMPTY}
137-
... value
138-
...
139-
... value3
140-
141-
To be more explicit, this transformer replace such values with ``${EMPTY}`` variables::
142-
143-
*** Variables ***
144-
${EMPTY_VALUE} ${EMPTY}
145-
@{EMPTY_LIST} @{EMPTY}
146-
&{EMPTY_DICT} &{EMPTY}
147-
@{LIST_WITH_EMPTY}
148-
... value
149-
... ${EMPTY}
150-
... value3
151-
152-
New transformer GenerateDocumentation (#311)
153-
--------------------------------------------
154-
155-
Transformer that allows you to generate keyword documentation stubs based on the keyword data such as
156-
name, arguments or returned values. It uses Jinja templating internally and allows to define your own
157-
documentation templates. With default template (Google docstring) and following code::
158-
159-
*** Keywords ***
160-
Keyword
161-
[Arguments] ${arg}
162-
${var} ${var2} Step
163-
RETURN ${var} ${var2}
164-
165-
it will generate::
166-
167-
*** Keywords ***
168-
Keyword
169-
[Documentation]
170-
...
171-
... Arguments:
172-
... ${arg}:
173-
...
174-
... Returns:
175-
... ${var}
176-
... ${var2}
177-
[Arguments] ${arg}
178-
${var} ${var2} Step
179-
RETURN ${var} ${var2}
180-
181-
Read the transformer documentation for more details on configuring your own custom template.
182-
183-
New transformer NormalizeComments (#290)
184-
-----------------------------------------
185-
186-
``NormalizeComments`` handles comments formatting. For now, it only focuses on fixing ``missing-space-after-comment``
187-
rule violations from the Robocop::
188-
189-
*** Settings ***
190-
#linecomment
191-
### header
192-
193-
194-
*** Keywords ***
195-
Keyword
196-
Step #comment
197-
198-
will be transformed to::
199-
200-
*** Settings ***
201-
# linecomment
202-
### header
203-
204-
205-
*** Keywords ***
206-
Keyword
207-
Step # comment
208-
```
209-
210274
Group comments with settings in OrderSettings (#468)
211275
----------------------------------------------------
212276

0 commit comments

Comments
 (0)