Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
gohierf opened this issue Sep 2, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@gohierf
Copy link

gohierf commented Sep 2, 2024

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 gohierf added the bug Something isn't working label Sep 2, 2024
@bhirsz
Copy link
Member

bhirsz commented Sep 2, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants