(structName, goFieldName, tagType string, field *ast.Field, tokenPos token.Pos, pass *analysis.Pass, allowedTypes map[string]bool, omitempty, omitzero bool)
| 249 | } |
| 250 | |
| 251 | func checkGoFieldType(structName, goFieldName, tagType string, field *ast.Field, tokenPos token.Pos, pass *analysis.Pass, allowedTypes map[string]bool, omitempty, omitzero bool) { |
| 252 | if allowedTypes[structName+"."+goFieldName] { |
| 253 | return |
| 254 | } |
| 255 | switch { |
| 256 | case omitzero: |
| 257 | skipOmitzero := checkAndReportInvalidTypesForOmitzero(structName, tagType, goFieldName, field.Type, tokenPos, pass) |
| 258 | if !skipOmitzero { |
| 259 | const msg = `the %q field in struct %q uses "omitzero"; remove "omitzero", as it is only allowed with structs, maps, and slices` |
| 260 | pass.Reportf(tokenPos, msg, goFieldName, structName) |
| 261 | } |
| 262 | |
| 263 | case omitempty: |
| 264 | if newFieldType, ok := checkAndReportInvalidTypes(structName, tagType, goFieldName, field.Type, tokenPos, pass); !ok { |
| 265 | const msg = `change the %q field type to %q in the struct %q because its %v tag uses "omitempty"` |
| 266 | pass.Reportf(tokenPos, msg, goFieldName, newFieldType, structName, tagType) |
| 267 | } |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | func checkAndReportInvalidTypes(structName, tagType, goFieldName string, fieldType ast.Expr, tokenPos token.Pos, pass *analysis.Pass) (newFieldType string, ok bool) { |
| 272 | switch ft := fieldType.(type) { |
no test coverage detected
searching dependent graphs…