robotframework-tidy icon indicating copy to clipboard operation
robotframework-tidy copied to clipboard

[Bug] Syntax errors can be recognized as EmptyLine

Open bhirsz opened this issue 2 years ago • 1 comments

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:
![image](https://user-images.githubusercontent.com/8532066/175265516-19dc0e25-6bf5-4876-b0d8-c45c18a22183.png)

It will result in transformers handling it as EmptyLine (currently NormalizeNewLines will remove such lines from the code).

bhirsz avatar Jun 23 '22 09:06 bhirsz

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()

bhirsz avatar Jun 23 '22 09:06 bhirsz

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.

bhirsz avatar Mar 24 '23 09:03 bhirsz