Closed flimzy closed 9 months ago
Describe the bug
revive incorrectly suggests replacing duplicated struct tags with string constants, for tags found in anonymous struct literals.
Example file to reproduce:
package test func x() { a := struct { X int `json:"x"` }{} b := struct { X int `json:"x"` }{} c := struct { X int `json:"x"` }{} _, _, _ = a, b, c }
To Reproduce Steps to reproduce the behavior:
go install github.com/mgechev/revive@latest
# flags revive -config config.toml .
Output:
test.go:13:9: string literal `json:"x"` appears, at least, 3 times, create a named constant for it
[rule.add-constant]
Expected behavior Struct tags in anonymous struct literals should be ignored by this rule, as they are for struct type definitions.
Thanks for detailed reporting. Have you tried doing the same using var with a zero value instead of assignment? It should work the same way but shouldn't trigger a warning.
cc @flimzy @chavacava
Describe the bug
revive incorrectly suggests replacing duplicated struct tags with string constants, for tags found in anonymous struct literals.
Example file to reproduce:
To Reproduce Steps to reproduce the behavior:
go install github.com/mgechev/revive@latest
Output:
Expected behavior Struct tags in anonymous struct literals should be ignored by this rule, as they are for struct type definitions.