Go Test Files showing violation for main source rules

Template for a good new topic, formatted with Markdown:

  • ALM used: Bitbucket Cloud
  • CI system used: Bitbucket Cloud
  • Scanner command used when applicable
  • Languages of the repository: Go
  • Error observed: None
  • Steps to reproduce: None
  • Potential workaround
    • Remove sonar.tests from sonar-project.properties
    • Add sonar.exclusions=**/*_test.go into sonar-project.properties

Do not share screenshots of logs – share the text itself (bonus points for being well-formatted)!

Started last week, we are observed there is a behavioral changes in our Golang repositories.

On all our PR scan, suddenly we saw surge of code smells pop out from our go test file. After looking into details, the rule that violated is supposedly only to being used at main sources and not test files.

Hi,

You list removing sonar.tests as a workaround. Does that mean you’ve tired it? That only when the files are explicitly listed as tests are they 1) picked up and 2) scanned with this rule?

Can you provide your analysis log?

The analysis / scanner log is what’s output from the analysis command. Hopefully, the log you provide - redacted as necessary - will include that command as well.

This guide will help you find them.

 
Thx,
Ann

Hi,

Thank you for replying.

Yes we already tried it. Originally our properties file will have
sonar.tests properties and it is able to pick up the test file, however since last week all of the file is being scanned with Rules that supposed only for Main Source (not including test file) that you can see on the screenshot (rule go:S1192)
From my understanding rule mentioned above should not being scanned for test file (because it is never do before last week, and it is failing across all of our go repository)

This is small snapshot of the log before we do the workaround, I will try to get the full log if possible from my end.

Hi,

Thanks for the log snippet. That’s already very helpful. This sounds like a rule behavior change, and I’m not easily finding any announcements related to that. I’ve flagged this for the language experts, but please do keep digging for your full analysis log in case they need it.

 
Thx,
Ann

Hello @madyatma,

thanks for the report!

Indeed we changed the behavior of the Go analyzer, to now handle Go test files in a different way.

We basically did two changes:

  1. Automatic test file detection in case users don’t define sonar.tests properties
  2. Analyze specific rules for Go test files, which were previously ignored

However on the second point, there seems to be some bug in the analyzer, which results in all rules being executed on test files.

We’ll fix this shortly and report back once we deploy it on SQC.

1 Like