We have noticed something in sonar scanner. If we add the #NOSONAR to a particular line in the file then sonar scanner ignores that line. But if we add a comment within a comment like // #NOSONAR
then sonarqube ignores the entire file.
Is this a bug or something? Please help.
The “//” is not a valid Python syntax as far as I remember, this is why the whole file is ignored. You can’t use // # NOSONAR because it isn’t valid Python code (again, as far as I remember).
I’m not sure what exactly happening to you but here are some facts:
Comment containing “NOSONAR” will make all issues on this line disappear
There is no such comment that will make entire file ignored (probably you just had parsing error). To do that you can rely on sonar.exclusions to completely exclude file from analysis. Also you can mark some file(s) to be ignored by particular rule(s) through SonarQube UI (see docs “Ignore Issues”)
I am going to suggest that if you want your question answered swiftly, you
don’t suggest the person helping you hasn’t done their due diligence to test your scenario with the information available
include information like your SonarQube version and SonarPython version
upload logs from your analysis attempts where you face this issue
upload a zipped up reproducer including the exact files you are facing this issue with and a sonar-project.properties file containing any additional analysis parameters you pass the scanner
Reproducing the issue should be as simple as navigating to the unzipped directory and running ‘sonar-scanner’
This forum is community support — not paid support. The bandwidth for individuals to answer your questions and investigate your issues can be increased by giving back to the community and answering some questions yourself! It’s also a great way to become a SonarQube expert.
I created two simple files with issues, then I added the NOSONAR comment to one issue and the other one is still being reported.
BUT I noticed in your examples you mixed “straight double quote” and “curly double quote”:
Maybe this is your problem. The “curly double quote” can’t be used for comments, it isn’t recognized by the Python interpreted and your code won’t execute. This causes a parser failure in the SonarPython analyzer and it’ll ignore the whole file as mentioned by @Lena.
I couldn’t reproduce your issue with the PHP code. Are you sure that your PHP code executes correctly after you add the NOSONAR comment?
Also, please check if you have set anything in Administration > Analysis Scope > “Ignore issues on files”. It shouldn’t contain the word NOSONAR.