Must-share information (formatted with Markdown):
- which versions are you using: SonarQube Enterprise v10.6
- how is SonarQube deployed: Cloud (?). No idea.
- what are you trying to achieve: To avoid incorrect SonarQube reports
- what have you tried so far to achieve this: I don’t think there is much I can do…
Hello,
We’re using SonarQube through the cloud in our company to analyze Python code (Python 3.9).
My apologies if this issue has been reported somewhere else - I have searched the archives and I have seen it for other languages, but I couldn’t find anything specific to Python (but maybe it’s my lack of searching skills).
SonarQube insists on reporting incorrect issues related to Python - specifically pythonbugs:2589 (Boolean expressions should not be gratuitous) by returning this:
Fix this expression which always evaluates to “true”
Or this:
Fix this expression which always evaluates to “false”
This is a simplified example:
def example(param1, param2):
if not param1 or (param1 and param2):
print('Return True')
return True
print('Return False')
return False
SonarQube tells me this:
However, running the simple function like this:
example(True, True)
example(False, True)
example(True, False)
example(False, False)
Does not always print Return True
:
C:\XXXX\python.exe C:\YYYY\sonarqube_test.py
Return True
Return True
Return False
Return True
I welcome any suggestion - and potential workarounds if you are aware of any of them. My knowledge of SonarQube is extremely limited. Thank you in advance.
Andrea.