Sonar.go.exclusions top level directory matching issue

We have some generated code that we want to exclude from analysis as such we have this property in our sonar-project.properties:

sonar.go.exclusions =\
  test/mock/**/*mock.go,\
  **/*.event_type.go,\
  **/*.pb.go,\
  **/*_test.go,\
  **/vendor/**

The *.pb.go and *_test.go files are not present in the SonarCloud reports but the *mock.go files under the test/mock/ subdirectories are still being reported.

For the sonar.exclusions property we also have some files that use a top level directory and this is excluded correctly so we suspect that the pattern matching for sonar.go.exclusions is not working consistently:

sonar.exclusions = \
  _tools/**,\
  **/vendor/**,\
  **/.vendor-new/**

We did some experiments and changing the pattern from test/mock/**/*mock.go to **/test/mock/**/*mock.go is working.

Hi,

I don’t recognize the sonar.go.exclusions property. In fact, you’ll need to set these exclusions with the rest of them in sonar.exclusions.

 
HTH,
Ann

Ann, yes using sonar.exclusions would be an option but sonar.go.exclusions is a valid property. See this screenshot from the language setting in SonarCloud:

We have a workaround which is to do this:

sonar.go.exclusions =\
  **/test/mock/**/*mock.go,\
  **/*.event_type.go,\
  **/*.pb.go,\
  **/*_test.go,\
  **/vendor/**

We believe that the rule test/mock/**/*mock.go should have worked without the need to add **/ in front of it.

Thanks for the correction @sodul! (I’m so glad I said I didn’t recognize it rather than saying it wasn’t valid. :sweat_smile:)

I’m glad you worked through this.