SonarQube Go Plugin reports false critical issue for json struct tag

  • Version 6.7.3 (build 38370)
  • Sonar reports duplicate literal for json struct tags used in GoLang. I think there should be an option to either ignore all the json tags in GoLang, or by default sonar should not mark json tag strings as having duplicate string literal.

Example code below:

   type AccessRequest struct {
   Id     string `json:"id"`
   Name   string `json:"name"`
   Status string `json:"status"`
   }

In above example if there are multiple structs which has “json:"status"”, then sonar will report it as critical issue. Like below:

   Define a constant instead of duplicating this literal 4 times.
   Code SmellCritical

Please provide a way to ignore this or ignore this by default.

Hello @unni

I agree with you, since there is no way to define a constant for such duplicated tag, we should not report an issue for this.

I created a ticket (SONARSLANG-486) to track this problem.

In the meantime, I suggest you to resolve the issue as false positive/ won’t fix.

Thanks for the feedback.

Quentin