Skip to content

NormalizeSeparators

Normalize separators and indents.

Disabling the formatter

NormalizeSeparators is included in the default formatters, but it can be also run separately with:

robocop format --select NormalizeSeparators

You can also disable it:

robocop format --configure NormalizeSeparators.enabled=False

All separators (pipes included) are converted to fixed length of 4 spaces (configurable via global option --space-count). To separately configure the indentation, use --indent global option.

Note

There are formatters that also affect separator lengths - for example AlignSettingsSection. NormalizeSeparators is used as a base and then potentially overwritten by behaviours of other formatters. If you only want to have fixed separator lengths (without aligning) then only run this formatter without running the others.

*** Settings ***
Library  library.py  WITH NAME          alias

Force Tags           tag
...   tag

Documentation  doc
...      multi
...  line

*** Test Cases ***
Test case
  [Setup]  Keyword
   Keyword  with  arg
   ...  and  multi  lines
     [Teardown]          Keyword

Test case with structures
    FOR  ${variable}  IN  1  2
    Keyword
     IF  ${condition}
       Log  ${stuff}  console=True
  END
   END
*** Settings ***
Library    library.py    WITH NAME    alias

Force Tags    tag
...    tag

Documentation    doc
...    multi
...    line

*** Test Cases ***
Test case
    [Setup]    Keyword
    Keyword    with    arg
    ...    and    multi    lines
    [Teardown]    Keyword

Test case with structures
    FOR    ${variable}    IN    1    2
        Keyword
        IF    ${condition}
            Log    ${stuff}    console=True
        END
    END

Configure separator

By configuring a global option space-count, you can change the default separator length:

robocop format --space-count 8
[tool.robocop.format]
space-count = 8

will result in:

*** Settings ***
Library  library.py  WITH NAME          alias

Force Tags           tag
...   tag
*** Settings ***
Library        library.py        WITH NAME        alias

Force Tags        tag
...        tag

Indentation

By default, indentation is the same as space-count value (default 4 spaces). To configure it, use --indent:

robocop format --indent 4
[tool.robocop.format]
indent = 4

Combine it with space-count to set whitespace separately for indent and separators:

robocop format --indent 4 --space-count 2
[tool.robocop.format]
indent = 4
space-count = 2

this configuration will result in:

*** Keywords ***
Keyword
  FOR     ${var}  IN RANGE     10
    Keyword With  ${var}
  END
*** Keywords ***
Keyword
    FOR  ${var}  IN RANGE  10
        Keyword With  ${var}
    END

Flatten multi line statements

By default NormalizeSeparators only updates the separators and leave any multi line intact. It is possible to flatten multi line statements into single line using flatten_lines option:

robocop format -c NormalizeSeparators.flatten_lines=True
[tool.robocop.format]
configure = [
    "NormalizeSeparators.flatten_lines=True"
]

will result in:

*** Keywords ***
Keyword
    Keyword Call    1  2
      ...    1  # comment
    ...    2          3
*** Keywords ***
Keyword
    Keyword Call    1    2
    ...    1    # comment
    ...    2    3
*** Keywords ***
Keyword
    Keyword Call    1    2    1    2    3  # comment

Align new lines

It is possible to align new lines to the first line. This alignment will be overwritten if you have formatters affecting alignment enabled, such as:

  • AlignKeywordsSection
  • AlignSettingsSection
  • AlignTemplatedTestCases
  • AlignTestCasesSection
  • AlignVariablesSection

You can enable it using align_new_line parameter:

robocop format --configure NormalizeSeparators.align_new_line=True
[tool.robocop.format]
configure = [
    "NormalizeSeparators.align_new_line=True"
]

will result in:

*** Test Cases ***
Test
    [Tags]    tag
    ...  tag2

*** Keywords ***
Keyword
    [Arguments]    ${argument1}
    ...    ${argument2} ${argument3}
    Keyword Call    argument
    ...  arg2
    ...    arg3
*** Test Cases ***
Test
    [Tags]    tag
    ...    tag2

*** Keywords ***
Keyword
    [Arguments]    ${argument1}
    ...    ${argument2}   ${argument3}
    Keyword Call    argument
    ...    arg2
    ...    arg3
*** Test Cases ***
Test
    [Tags]    tag
    ...       tag2

*** Keywords ***
Keyword
    [Arguments]    ${argument1}
    ...            ${argument2}   ${argument3}
    Keyword Call    argument
    ...             arg2
    ...             arg3

Skip formatting

It is possible to use the following arguments to skip formatting of the code:

Documentation is not formatted by default. To enable formatting the separators inside documentation, set skip_documentation to False:

robocop format --configure NormalizeSeparators.skip_documentation=False
[tool.robocop.format]
configure = [
    "NormalizeSeparators.skip_documentation=False"
]

will result in:

TEST_TC
    [Argument]    ${a}    ${long_arg}
    [Documentation]     Test Doc.
    ...
    ...    Arguments:
    ...    a:               Argument A
    ...    long_arg:        Argument long_arg.
   Test Case Body
TEST_TC
    [Argument]    ${a}    ${long_arg}
    [Documentation]     Test Doc.
    ...
    ...    Arguments:
    ...    a:               Argument A
    ...    long_arg:        Argument long_arg.
   Test Case Body
TEST_TC
    [Argument]    ${a}    ${long_arg}
    [Documentation]     Test Doc.
    ...
    ...    Arguments:
    ...    a:    Argument A
    ...    long_arg:    Argument long_arg.
   Test Case Body

It is also possible to use disablers but skip option makes it easier to skip all instances of a given type of the code.