MarketSquare / robotframework-tidy

Robot Framework code formatter
https://robotidy.readthedocs.io/
Apache License 2.0
105 stars 17 forks source link

NormalizeSeparators with pipe separators silently fails with param sections=comments #385

Closed glueologist closed 2 years ago

glueologist commented 2 years ago

Trying to fine tune the run of just NormalizeSeparators on resource file with large comments. The doc on Ignored Sections shows that the only the sections listed in the 'sections' param will get transformed.

If I list all sections but comments all lines are transformed. This might be because I do not understand what is considered a comment section. If I am correct than this usage of 'sections' param is broken too.

But if sections param only has 'comments' no output is produced and return code is 0 (zero)

Orig file:

*** Settings ***
| Documentation
| ... | Provides access to all Keywords needed for interaction with Toucan GUI.
| ... | For more details on what must be set to use this library, see documentation
| ...
| Library   | String
| Library   | Collections
| Library   | SensorSwitchRig
| ... | gmswRig | 001
| Resource  | vertiv_lol_sensor_rig.robot
| Variables | geist_toucan_constants.py

*** Keywords ***

#------------------------------------------------------------------#
# A LARGE COMMENT SECTION                                          #
#                                                                  #
# Used to do a complete set and verify of a Toucan param           #
#------------------------------------------------------------------#

#
# Text Fields
#
Test Toucan Text Field
| | [Documentation] | Sets and verifies Toucan GUI text fields against expected value.
| | ... | \nExample:
| | ... | \| \| Test Toucan Text Field  \| webserver \| httpport  \| ${value} \| ${expected}
| | [Arguments] | ${page name} | ${field name} | ${value} | ${expected}=${G_NOT_DEFINED}
| | Set And Save Toucan Field Type | text | ${page name} | ${field name} | ${value}
| | Verify Param Without Login | ${page name} | ${field name} | ${value} | ${expected}

With all sections but comments. Expectation is all pipes removed with 4 spaces but large block comment is not changed.

robotidy  --output out.robot  --transform NormalizeSeparators:sections=settings,variables,keywords,testcases in.robot
cat out.robot

*** Settings ***
Documentation
...    Provides access to all Keywords needed for interaction with Toucan GUI.
...    For more details on what must be set to use this library, see documentation
...
Library    String
Library    Collections
Library    SensorSwitchRig
...    gmswRig    001
Resource    vertiv_lol_sensor_rig.robot
Variables    geist_toucan_constants.py

*** Keywords ***

#------------------------------------------------------------------#
# A LARGE COMMENT SECTION    #
#    #
# Used to do a complete set and verify of a Toucan param    #
#------------------------------------------------------------------#

#
# Text Fields
#
Test Toucan Text Field
    [Documentation]    Sets and verifies Toucan GUI text fields against expected value.
    ...    \nExample:
    ...    \| \| Test Toucan Text Field  \| webserver \| httpport  \| ${value} \| ${expected}
    [Arguments]    ${page name}    ${field name}    ${value}    ${expected}=${G_NOT_DEFINED}
    Set And Save Toucan Field Type    text    ${page name}    ${field name}    ${value}
    Verify Param Without Login    ${page name}    ${field name}    ${value}    ${expected}

With only comments given there is no output and RC=0

robotidy  --output out.robot  --transform NormalizeSeparators:sections=comments in.robot

echo $?
0

cat out.robot
cat: out.robot: No such file or directory

I tried the same using a configure file and the results are the same:

PRODUCES NO OUTPUT

cat comments.toml

[tool.robotidy]
separator = "space"
spacecount = 4

transform = [
    "NormalizeSeparators:sections=comments"
]

PRODUCES OUTPUT AS GIVEN ABOVE:

cat nocomments.toml

[tool.robotidy]
separator = "space"
spacecount = 4

transform = [
    "NormalizeSeparators:sections=settings,variables,keywords,testcases"
]
bhirsz commented 2 years ago

I have added in 3.0 release skip_* parameters. I think - when you mention this transformer and behavior of the section - I should replace it with skip_section in the future. I will open issue for it. But that's for the next major release.

For the issue itself - the comments is Comments section. Every line before first section in the file is considered as part of the comment section - and it can optionally have header Comments . When I will be near PC I can check if the transformer skip it properly and section parameter is honored.

If you want to skip comments (the ones with #) in NormalizeSeparator we would need to add new skip_* parameter. It could be either skip_comment skipping all comments or skip_standalone_comments - bit verbose but a way to skip lines containing only comments.

glueologist commented 2 years ago

Sounds good. I will test the Comments section tomorrow and let you know. Expect it should work.

bhirsz commented 2 years ago

Opened separated issue to track mentioned future changes, closing this issue for now (reopen if needed).