Skip to content

0509 fails at Comments section  #234

@szabolcstoth

Description

@szabolcstoth

Describe the bug
I started to play with issue #174 and I ran into an issue.
If data is defined before the first data section, that part counts as Comments section (lines are considered as COMMENT tokens).
Currently, the mentioned 0509 Section is empty rule will fail for Comments section unless there is only one line which starts with robocop: string due to the check_if_empty function.

for child in node.body:
    if isinstance(child, Comment):
        if 'robocop:' in child.tokens[0].value and len(node.body) == 1:
            break
        elif not isinstance(child, EmptyLine):
            break
    else:
        self.report("empty-section", node=node)

To Reproduce
You can reproduce the issue with this test code:

Data before the first section is ignored in Robot Framework.
Second line in Comment section.

*** Settings ***
Documentation    Dummy documentation.


*** Test Cases ***
Dummy Test Case
    [Documentation]    Dummy documentation.
    No Operation

This one will pass.

robocop:Data before the first section is ignored in Robot Framework.
*** Settings ***
Documentation    Dummy documentation.


*** Test Cases ***
Dummy Test Case
    [Documentation]    Dummy documentation.
    No Operation

Expected behavior
I suppose we should handle Comments section like the others.

Additional context
Is there any particular reason why the check_if_empty function was implemented this way?
If this is a bug, it should be an easy fix by removing the if 'robocop: ... part, I can do a pull request for it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions