Skip to content

RenameKeywords

Enforce keyword naming. Title Case is applied to the keyword name and underscores are replaced by spaces. It has only basic support for keywords with embedded variables - use it at your own risk.

Enabling the formatter

RenameKeywords is not included in default formatters.

You can enable it by using --select and --extend-select options.

robocop format --select RenameKeywords
robocop format --extend-select RenameKeywords

You can keep underscores if you set remove_underscores to False:

robocop format --select RenameKeywords -c RenameKeywords.remove_underscores=False
[tool.robocop.format]
select = [
    "RenameKeywords"
]
configure = [
    "RenameKeywords.remove_underscores=False"
]

Keyword case

By default, each word in the keyword case is capitalized. It can be configured using keyword_case parameter:

*** Keywords ***
keyword name
    Log    ${GLOBAL}
    perform Action
*** Keywords ***
Keyword Name
    Log    ${GLOBAL}
    Perform Action
*** Keywords ***
Keyword name
    Log    ${GLOBAL}
    Perform Action
*** Keywords ***
keyword name
    Log    ${GLOBAL}
    perform Action

Case normalization

When converting the case, only the affected letter (first in sentence or first of each word) is affect. This is controled by case_normalization parameter (default "first_letter"):

*** Keywords ***
keyword name
    Keyword Call
    EXECUTE actioN
*** Keywords ***
Keyword Name
    Keyword Call
    EXECUTE ActioN
*** Keywords ***
Keyword Name
    Keyword Call
    Execute Action
*** Keywords ***
Keyword name
    Keyword call
    Execute action

Use skip_keyword_call to ignore case normalization on selected keyword calls.

Library name

By default, the library name in the keyword name is ignored. Anything before the last dot in the name is considered as a library name. Use ignore_library = True parameter to control if the library name part (Library.Keyword) of keyword call should be renamed.

*** Keywords ***
Keyword
    library_name.keyword
*** Keywords ***
Keyword
    library_name.Keyword
*** Keywords ***
Keyword
    Library Name.Keyword

Replace pattern

It is also possible to configure replace_pattern parameter to find and replace regex pattern. Use replace_to to set replacement value. This configuration (underscores are used instead of spaces):

robocop format --select RenameKeywords -c RenameKeywords.replace_pattern=(?i)^rename\s?me$ -c RenameKeywords.replace_to=New_Shining_Name
[tool.robocop.format]
select = [
    "RenameKeywords"
]
configure = [
    "RenameKeywords.replace_pattern=(?i)^rename\\s?me$",
    "RenameKeywords.replace_to=New_Shining_Name"
]

replaces all occurrences of name Rename Me (case-insensitive thanks to (?i) flag) to New Shining Name:

*** Keywords ***
rename Me
   Keyword Call
*** Keywords ***
New Shining Name
    Keyword Call

This feature makes this formatter a convenient tool for renaming your keywords across a Robot Framework project.