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.