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

[Bug] Argument overwritten inside a conditional statement should not raise W0921

Open gohierf opened this issue 1 year ago • 1 comments

What happened?

argument-overwritten-before-usage / W0921 is raised when overriding an argument in a conditional statement. The override was on purpose and the warning should not be raised.

image

What command/code did you try to run?

My Keyword
    [Documentation]    argument conditionnaly changed still shows
    ...    argument-overwritten-before-usage / W0921
    [Arguments]    ${to print}    ${another arg}
    IF    ${another arg} != "KEEP"
        VAR    ${to print}    "overwrite"
    END
    Log To Console    ${to print}

What is the full error message?

Keyword argument '${to print}' is overwritten before usagerobocop argument-overwritten-before-usage-W0921

What did you expect to happen instead?

The rule could assume that if the variable is overwritten from inside an IF clause, it is on purpose.

Operating System

Windows

Robocop version

5.0.4

gohierf avatar Sep 02 '24 10:09 gohierf

That rule is bit tricky because there could be numerous reasons for variable being overwritten. The purpose was mainly to catch 'useless' arguments, for example that are always overwritten without being used.

But I agree if there is any condition, the issue shouldn't be raised - since the argument is not always overwritten but only in some cases.

bhirsz avatar Sep 02 '24 10:09 bhirsz