RenameVariables¶
Rename and normalize variable names.
Enabling the formatter
RenameVariables is not included in default formatters.
You can enable it by using --select and --extend-select options.
Variable names in the Settings, Variables, Test Cases and Keywords section are renamed. Variables in arguments are also affected.
The following conventions are applied:
- the variable case depends on the variable scope (lowercase for local variables and uppercase for non-local variables)
- leading and trailing whitespace is stripped
- more than 2 consecutive whitespace in name is replaced by 1
- whitespace is replaced by _
- camelCase is converted to snake_case
Conventions can be configured or switched off using parameters.
Note
RenameVariables is still under development and is not considered a complete feature. The following syntax is not yet supported:
- variables passed by variable, not value (
$var) are ignored
Robocop can be locally disabled with # robocop format: off if you want to ignore specific cases.
Variable case in the Settings section¶
All variables in the *** Settings *** section are formatted to uppercase. This behaviour is configurable
using settings_section_case:
Allowed values are:
upper(default) to uppercase nameslowerto lowercase namesignoreto leave an existing case
Variable case in Variables section¶
All variables in the *** Variables *** section are formatted to uppercase. This behaviour is configurable
using variables_section_case:
Allowed values are:
upper(default) to uppercase nameslowerto lowercase namesignoreto leave an existing case
Variable case in Keywords, Tasks and Test Cases sections¶
Variable case in *** Keywords ***, *** Tasks *** and *** Test Cases *** sections depends on the
variable scope. Local variables are lowercase and global variables are uppercase. Any unknown variable (not defined
in the current keyword or test case) is considered as global. You can configure what should happen with unknown variables using
unknown_variables_case:
Allowed values are:
upper(default) to uppercase unknown nameslowerto lowercase unknown namesignoreto leave an existing case
Scope of the variable can be also changed using Set Test/Task/Suite/Global Variable keywords and with Robot
Framework 7.0 VAR syntax using scope=local/TEST/TASK/SUITE/GLOBAL parameter.
Ignore variable case¶
Case of all variables is converted according to the configured conventions. It is possible to pass the names of the variables that should be ignored. By default, following variables case is ignored and not formatted:
${\n}${None}${True}${False}
Configure ignore_case to ignore an additional list. This parameter accepts a comma-separated list of variable names
(case-sensitive):
Converting camelCase to snake_case¶
Variable names written in camelCase are converted to snake_case. You can disable this behaviour by configuring
convert_camel_case to False:
will result in:
Renaming from camelCase to snake_case is usually safe except the variables passed as kwargs:
*** Keywords ***
Keyword
Keyword With Kwargs processValue=40
Keyword With Kwargs
[Arguments] ${with_default}=10 ${processValue}=10
Should Be Equal ${with_default} ${processValue}
In such case ${processValue} will be converted to ${process_value} but processValue from keyword call
will not be converted.
Variable separator¶
Separators inside variable name are converted to underscore (_). You can configure it using variable_separator:
Allowed values are:
underscore(default)spaceignore
Variable separator with math operators¶
Variable separator is not replaced when it is used in math expression:
Skip formatting¶
It is possible to use the following arguments to skip formatting of the code:
It is also possible to use disablers but skip option makes it easier to skip all instances of a given type
of the code.