robotframework-tidy
robotframework-tidy copied to clipboard
Add support for pipes as separator
Currently --separator option only supports space and tab.
It would be great if you could add pipe separator support.
I also agree, from other bug discussion, with overall methodology when dealing with anything other than a space separator: first normalize to space separator, run all desired transforms, than normalize back to what ever separator desired.
I would like to ask for this support to also support a specialized style of pipes. I use pipes for readablility in the code -- but removed them for docs of code -- and to help prevent lack of separator bugs.
To increase readability in the code I ONLY use pipes on the keyword and test case step rows. Pipes are not used on table names: Settings, Keywords, etc., nor are pipes used on Keyword and Test Case name row. Note I do not use the newer feature where KW name row can have other text. Been RF'ing since 2015 ;-). If robotidy sees KW or TC name lines with text and the specialized format was requested it could error out or ignore specialized format and put pipes in where required.
Style as from the RF user doc:
| *** Settings *** |
| Documentation | Example using the pipe separated format.
| Library | OperatingSystem
| *** Variables *** |
| ${MESSAGE} | Hello, world!
| *** Test Cases *** | | |
| My Test | [Documentation] | Example test. |
| | Log | ${MESSAGE} |
| | My Keyword | ${CURDIR} |
| Another Test | Should Be Equal | ${MESSAGE} | Hello, world!
| *** Keywords *** | | |
| My Keyword | [Arguments] | ${path} |
| | Directory Should Exist | ${path} |
My current style which is supported by the RF parser:
*** Settings ***
| Documentation | Example using the pipe separated format.
| Library | OperatingSystem
*** Variables ***
| ${MESSAGE} | Hello, world!
*** Test Cases ***
My Test
| | [Documentation] | Example test. |
| | Log | ${MESSAGE} |
| | My Keyword | ${CURDIR} |
Another Test
| | Should Be Equal | ${MESSAGE} | Hello, world!
*** Keywords ***
My Keyword
| | [Arguments] | ${path} |
| | Directory Should Exist | ${path} |
The support for pipes in --separator and what your'e asking in the later half of thread are two separate things.
For having auto formatter format some parts of the code with pipes and some with spaces it would be best to have specialized transformer for space->pipe conversion. This transformer will accept skip parameters (like some transformers, ie AlignTestCaseSection), ie skip_headers, skip_keyword_name. Those skip parameters does not exist yet but it should be fairly easy to add. You could then configure what part of Robot Framework syntax you want to skip when doing the space->pipe conversion.
Yea, now as I become more acquainted with the docs and the tool having skip parameters is the correct and consistent approach.
I am thinking about cloning and trying my hand at an External Transformer for adding pipes. Besides the docs do you know of an existing complete ET already done?
After writing above I decided to look at your code (as your doc states). Pretty straight forward.
I'm sure there are several ET implementations (since I had received bugs for it :D Same for external rules in Robocop..) but I didn't see them (except one that was later transferred to our core transformers). Creating a transformer is quite straightforward and if you want to create a core transformer (for robotidy) we have also invoke task for it (pip install invoke, call invoke add-transformer
. add --disabled
for non-default transformers). It will bootstrap new files in the robotidy project (transformer itself, docs files, tests in test/atest).
More problematic is usually understanding how Robot Framework ast works. Robotidy transformers can be used as a reference, though since RF allows for multiple ways of doing things, I often had to cover various edge cases that might make code less readable. At first you can assume that all your input contains only spaces (bit bold since transformers are independed so you can't be sure someone replaced pipes to spaces ;) But it's enough if it's mentioned in the docs). You also need to remember to retain the length of the separator (in case you have some manual spacing / or aligner spacing that you want to keep).
There is small edge case. This:
| |
It is typically two separator (|
) in Robot Framework while when you're using spaces it will be just one. The question is - can you replace it with single separator (` | | ``) or you need to create two separators? Most likely the first option - the second will be harder to do (because you then need to count the indent level to know how many separators to use).
I'm sure there are several ET implementations (since I had received bugs for it :D Same for external rules in Robocop..) but I didn't see them (except one that was later transferred to our core transformers). Creating a transformer is quite straightforward and if you want to create a core transformer (for robotidy) we have also invoke task for it (pip install invoke, call
invoke add-transformer
. add--disabled
for non-default transformers). It will bootstrap new files in the robotidy project (transformer itself, docs files, tests in test/atest).More problematic is usually understanding how Robot Framework ast works. Robotidy transformers can be used as a reference, though since RF allows for multiple ways of doing things, I often had to cover various edge cases that might make code less readable. At first you can assume that all your input contains only spaces (bit bold since transformers are independed so you can't be sure someone replaced pipes to spaces ;) But it's enough if it's mentioned in the docs). You also need to remember to retain the length of the separator (in case you have some manual spacing / or aligner spacing that you want to keep).
There is small edge case. This:
| |
It is typically two separator (
|
) in Robot Framework while when you're using spaces it will be just one. The question is - can you replace it with single separator (` | | ``) or you need to create two separators? Most likely the first option - the second will be harder to do (because you then need to count the indent level to know how many separators to use).
For what its worth - it would be nice if this could implemented as you described here: https://groups.google.com/g/robotframework-users/c/Hhjp__px7U8
I would be another user of this to beautify pipe syntax. I see that we can replace pipes now with spaces, run the current transformers on the code to beautify, and replace spaces with the pipe syntax. Seems like a good approach, would appreciate this support.