Search code examples
javavisual-studio-codesonarlint

VS code - SonarLint:Simplify the expression produce invalid syntax


I'm getting S1125 for a code smell:

MyVO vo;
public boolean is() {
    return vo == null ? false : vo.is();
}

Remove the unnecessary boolean literal.sonarlint(java:S1125)

But when choosing Quick Fix -> SonarLint:Simplify the expression it return invalid java syntax:

return !vo == null && vo.is();

Is it Sonar Lint bug ? is my vs code settings is wrong?

Obviously it should fix to:

return vo != null && vo.is();

(Using latest VS code and sonar lint plugin)

I didn't find any issue in sonar community/Jira


Solution

  • Opened a question in Sonar community https://community.sonarsource.com/t/sonarlint-simplify-the-expression-wrong-syntax-on-java-s1125/62467

    Which reported as SONARJAVA-4241

    S1125: erroneous quick fix suggestion when negating a binary operation

    and probably will be removed

    It seems that covering all the cases seems tricky. We might want to simplify and simply don't suggest a quick fix if the expression is a binary operation.