Closed gohierf closed 1 month ago
'Popping out' comments is by design. Thanks for that we can ignore comments as it may be difficult to handle them in some cases (especially if for example we split into new lines etc). I need to think how to workaround this behaviour. It is doable to handle comments in transformer that indents run keywords (if its not different transformer like order settings) but I would need to see if its always applicable.
Returning to the issue. There is a problem that sometimes comments 'are in a way'. For example in your case, IndentNestedKeywords
may completely reorder the statement:
Run Keyword If True My Keyword ${arg} ELSE My Other Keyword # comment about this line
... random argument
Run Keywords # comment
... No Operation # comment
# No Operation
,,, No Operation No Operation No Operation # comment
Comments such as # No Operation
are clear but comments after data tokens are more difficult to handle (they usually need to stay close to the commented line). They way this transformation works is transforming everything to 'base' state and then reconstructing it with desired indent etc (and that's when 'popping' comments out happens).
I have some idea though - for example I can try to check if code before and after transformation was modified outside comments position. If not, we can ignore the transformation. I will work on this solution
I often use the Run Keywords methods for Setup or Teardown, sometimes I need to disable part of the setup/teardown, and I like to do this by just commenting the line(s) to disable.
Unfortunately, this doesn't work well with tidy... As the commented line is moved above the keyword/setting call.
Not sure which rule(s) is/are involved. But it seems related to keyword with sub-indentation.
For instance, in the example below, tidy does not change the location of
message B
ormessage 2
, which is what I am expecting. However, the commentedNo Operation
is moved around because it is withinRun Keywords
.This looks like a bug/undesired behavior, but it might be a question of configuring correctly one or more rules... Let me know!
Example code
Desired
After formatting