mirror of
https://github.com/mgechev/revive.git
synced 2025-11-23 22:04:49 +02:00
fix 208 struct-tag linter false positive (#209)
This commit is contained in:
@@ -86,7 +86,7 @@ func (w lintStructTagRule) checkTaggedField(f *ast.Field) {
|
||||
w.addFailure(f.Tag, "field's type and default value's type mismatch")
|
||||
}
|
||||
case "json":
|
||||
msg, ok := w.checkJSONTag(tag.Options)
|
||||
msg, ok := w.checkJSONTag(tag.Name, tag.Options)
|
||||
if !ok {
|
||||
w.addFailure(f.Tag, msg)
|
||||
}
|
||||
@@ -161,10 +161,15 @@ func (w lintStructTagRule) checkBSONTag(options []string) (string, bool) {
|
||||
return "", true
|
||||
}
|
||||
|
||||
func (w lintStructTagRule) checkJSONTag(options []string) (string, bool) {
|
||||
func (w lintStructTagRule) checkJSONTag(name string, options []string) (string, bool) {
|
||||
for _, opt := range options {
|
||||
switch opt {
|
||||
case "omitempty", "string":
|
||||
case "":
|
||||
// special case for JSON key "-"
|
||||
if name != "-" {
|
||||
return "option can not be empty in JSON tag", false
|
||||
}
|
||||
default:
|
||||
return fmt.Sprintf("unknown option '%s' in JSON tag", opt), false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user