Skip to content

[Bug] Rule I0924 expression-can-be-simplified, is raised when its not valid example ${VAR}==0 #1174

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

Open
IlfirinPL opened this issue Feb 13, 2025 · 5 comments
Labels
bug Something isn't working

Comments

@IlfirinPL
Copy link

IlfirinPL commented Feb 13, 2025

What happened?

Below Code where comparing ${VAR} to 0 is raised as it could be simplified. But when "simplified" will work incorrectly.
I personally use it for cases when I check return code from process ${result.rc}

What command/code did you try to run?

VAR    ${VAR}    0
Should Be True    ${VAR}==0    Error 1
Should Be True    ${VAR} == 0    Error 2
Should Be True    ${VAR}    Error 3

What is the full error message?

Error 3

What did you expect to happen instead?

I expect to not raise rule violation I0924 for ${VAR}==0

Operating System

N/A

Robocop version

5.8.1

@IlfirinPL IlfirinPL added the bug Something isn't working label Feb 13, 2025
@bhirsz
Copy link
Member

bhirsz commented Feb 13, 2025

I believe we have similiar issue in the backlog complaning about this rule - I need to make it as non-default because of such false positives.

In your example you can always do $VAR == 0 which probably will not trigger warning, but of course your code is also fine.

@IlfirinPL
Copy link
Author

In code also raise issue when "space" is added
IF ${result.rc} == 0

Image

@IlfirinPL
Copy link
Author

I will provide another example "expression-can-be-simplified", raise issue when its not valid

IF ${connected} == ${False}

@bhirsz
Copy link
Member

bhirsz commented Mar 15, 2025

I have removed 0 from condition of this rule as it was too often false positive. I also made rule non-default (opt-in).

One question:

IF ${connected} == ${False}

why following simplified condition is not valid?

IF    not $connected

@IlfirinPL
Copy link
Author

Its good question, this part should be auto transform :)
Since
IF ${connected} == ${False}
and
IF ${connected} == ${EMPTY}
will give the same results
as
IF not $connected

only against is that using ${VAR} syntax will rise issue
IF not ${connected}
will rise error
Invalid IF condition: Evaluating expression 'not ' failed: SyntaxError: invalid syntax (, line 1)

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