Skip to content

Commit

Permalink
fix: do not abort check on ignored fields (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
22dm authored Apr 7, 2024
1 parent 4026f8f commit d59fd57
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion musttag.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func (c *checker) checkStruct(styp *types.Struct, tag string) (valid bool) {

// Do not recurse into ignored fields.
if tagValue == "-" {
return true
continue
}

if valid := c.checkType(field.Type(), tag); !valid {
Expand Down
16 changes: 16 additions & 0 deletions testdata/src/tests/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,22 @@ func ignoredNestedType() {
json.Marshal(&Foo{}) // no error
}

func ignoredNestedTypeWithSubsequentNoTagField() {
type Nested struct {
NoTag string
}
type Foo struct {
Ignored Nested `json:"-"`
Exported string `json:"exported"`
NoTag string
}
var foo Foo
json.Marshal(foo) // want "the given struct should be annotated with the `json` tag"
json.Marshal(&foo) // want "the given struct should be annotated with the `json` tag"
json.Marshal(Foo{}) // want "the given struct should be annotated with the `json` tag"
json.Marshal(&Foo{}) // want "the given struct should be annotated with the `json` tag"
}

func interfaceSliceType() {
type WithMarshallableSlice struct {
List []Marshaler `json:"marshallable"`
Expand Down

0 comments on commit d59fd57

Please sign in to comment.