Skip to content

2.0.0

Compare
Choose a tag to compare
@bhirsz bhirsz released this 24 Mar 12:07
· 258 commits to main since this release
8ff6520

Robotidy 2.0

Major release of Robotidy that brings new transformers and features. It focuses on bringing support for
Robot Framework 5.0 new syntax such as BREAK, CONTINUE, RETURN statements or TRY EXCEPT block.
Also Robotidy documentation got several improvements and extra examples.

New Transformers

ReplaceReturns

Replaces return statements (such as [Return] setting or Return From Keyword keyword) with RETURN statement (#231).

Following code:

*** Keywords ***
Keyword
    Return From Keyword If    $condition    2
    Sub Keyword
    [Return]    1

Keyword 2
    Return From Keyword    ${arg}

will be transformed to:

*** Keywords ***
Keyword
    IF    $condition
        RETURN    2
    END
    Sub Keyword
    RETURN    1

Keyword 2
    RETURN    ${arg}

See https://robotidy.readthedocs.io/en/latest/transformers/ReplaceReturns.html for more examples

ReplaceBreakContinue

Replaces Continue For Loop and Exit For Loop keyword variants with CONTINUE and BREAK statements (#241).

Following code:

*** Keywords ***
Keyword
    FOR    ${var}    IN  1  2
        Continue For Loop
        Continue For Loop If    $condition
        Exit For Loop
        Exit For Loop If    $condition
    END

will be transformed to:

*** Keywords ***
Keyword
    FOR    ${var}    IN  1  2
        CONTINUE
        IF    $condition
            CONTINUE
        END
        BREAK
        IF    $condition
            BREAK
        END
    END

See https://robotidy.readthedocs.io/en/latest/transformers/ReplaceBreakContinue.html for more examples.

InlineIf

Replaces IF blocks with inline IF (#230).

Following code::

*** Test Cases ***
Test
    IF    $condition1
        Keyword    argument
    END
    IF    $condition2
        ${var}  Keyword
    ELSE
        ${var}  Keyword 2
    END
    IF    $condition1
        Keyword    argument
        Keyword 2
    END

will be transformed to:

*** Test Cases ***
Test
    IF    $condition1    Keyword    argument
    ${var}    IF    $condition2    Keyword    ELSE    Keyword 2
    IF    $condition1
        Keyword    argument
        Keyword 2
    END

You can decide to not replace IF blocks containing ELSE or ELSE IF branches by setting skip_else to True.

See https://robotidy.readthedocs.io/en/latest/transformers/InlineIf.html for more examples.

Changes in transformers

min_width parameter

New min_width parameter was added to AlignSettingsSection, AlignVariablesSection and AlignTestCases (#242).
It allows to set minimal width of data column instead of using width of the widest argument in the column.

Following code:

*** Variables ***
${var}    a
${var2}  b

would be aligned to ${var2} length since it's the longest token. If you wish to have fixed width you can use
min_width parameter:

robotidy --configure AlignVariablesSection:min_width=15

With such configuration previous code will be transformed to:

*** Variables ***
${var}         a
${var2}        b

Sections only with comments

Previously, sections that contained only comments and empty lines were removed by default by DiscardEmptySections. It
could be changed by configuring allow_only_comments to True. Since it wasn't expected behaviour by most users, now it
works in an opposite way - only the sections with comments will be removed by configuring allow_only_comments to False (#235).

Do not align variables with given types

New skip_types parameter in AlignVariablesSection which allows to not align variables of particular type (#225)

With following configuration:

    robotidy --configure AlignVariablesSection:skip_types=dict

All variables except dictionaries will be aligned.

SplitTooLongLine transformer

Several updates to SplitTooLongLine transformer.


Basic behaviour changed and now every statement that's longer than
character limit will be split to multiple lines:

Keyword With Longer Name
...    ${arg1}
...    ${arg2}
...    ${arg3}

If you wish to use previous algorithm of feeding arguments into one line until limit set split_on_every_arg to False:

Keyword With Longer Name    ${arg1}  # let's asumme that ${arg} is right below character limit
...    ${arg2}    ${arg3}

Assignments are now split (if they don't fit in one line):

${first_assignment}
...    ${second_assignment}
...    ${third_assignment}
...    Some Lengthy Keyword So That This Line Is Too Long And Bit Over

RenameKeywords transformer

Library names are now by default ignored by RenameKeywords transformer. Previously, it could result in an unexpected behaviour (#269).
If you want to transform library names pass ignore_library=False to transformer.

    custom_library.Keyword  # custom_library will be renamed to Custom Library only if you set `ignore_library` to False
    Other Keyword

Other

Overwrite files with --check flag

It is now possible to force overwrite with --check and --overwrite flags (#239).
Going over possible options:

Transform the files and return 0 even if there were files transformed.

robotidy src

Don't transform the files and return 0 even if there would be files transformed

robotidy --no-overwrite src

Don't transform the files and return 1 if there would be files transformed

robotidy --check src

Transform the files and return 1 if there are files transformed

robotidy --check --overwrite src

User-friendly exceptions

Changed exceptions to be more user-friendly. Robotidy will try to recognize common mistakes.
For unknown issues there is an extra message with link to our bug board (#250)

Previously, typos or common mistakes resulted in an error stack being printed - often without clear information what went wrong.
Now Robotidy tries to output the reason of a failure:

> robotidy --transform InlineI:line_length=100 .
Error: Importing transformer 'InlineI' failed. Verify if correct name or configuration was provided. Did you mean:
    InlineIf

> robotidy --diff --transform InlineIf:line-len=100 .
Error: InlineIf: Failed to import. Verify if correct name or configuration was provided. This transformer accepts following arguments:
    line_length
    skip_else

> robotidy --diff --transform InlineIf:line_lengthn=abc .
Error: InlineIf: Failed to import. Verify if correct name or configuration was provided. 
Argument 'line_length' got value 'abc' that cannot be converted to integer or None.

Changes to acceptance tests

Refactored Robotidy acceptance tests (#248).

Fixes

  • Unmodified files are now not saved to the disk (#237)

Acknowledgements

Thanks @DetachHead and @ealap for reporting issues and ideas.