robotframework-tidy
robotframework-tidy copied to clipboard
[Bug] Syntax errors can be recognized as EmptyLine
Following code:
*** Keywords ***
Keyword
var
${var}
${one} ${two}
```
is syntax error (``${var}`` is assign but there is no keyword call). It will be recognized as EmptyLine by Robot Framework:

It will result in transformers handling it as EmptyLine (currently NormalizeNewLines will remove such lines from the code).
It's most likely the change in Robot Framework 5.0. Since it's not something that should happen often (it's happens with syntax error) I'm descoping it from the next release in hope it will be fixed in core robot.
Example code that could work as workaround if they will not fix it:
@staticmethod
def trim_trailing_empty_lines(node):
if not hasattr(node, "body"):
return
last_index = 1
while len(node.body) >= last_index and isinstance(node.body[-last_index], EmptyLine):
# if EmptyLines contains non-data tokens, it is syntax error we want to skip
if any(token.value not in Token.NON_DATA_TOKENS for token in node.body[-last_index].tokens):
last_index += 1
else:
node.body.pop()
Closing the issue - the problem was in the Robot Framework code (which was fixed). We cannot safeguard from such issues and if the user encounters such cases, he just need to use different RF version.