Skip to content

Commit

Permalink
Update errchkjson to v0.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
breml committed Nov 7, 2021
1 parent 77a07b2 commit 4c161ac
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ require (
github.com/blizzy78/varnamelen v0.4.0
github.com/bombsimon/wsl/v3 v3.3.0
github.com/breml/bidichk v0.1.1
github.com/breml/errchkjson v0.1.0
github.com/breml/errchkjson v0.1.1
github.com/butuzov/ireturn v0.1.1
github.com/charithe/durationcheck v0.0.9
github.com/daixiang0/gci v0.2.9
Expand Down
4 changes: 2 additions & 2 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions test/testdata/errchkjson.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ func JSONMarshalUnsafeTypes() {
var err error

var f32 float32
json.Marshal(f32) // ERROR "Error return value of `encoding/json.Marshal` is not checked: unsafe type `float32` found"
_, _ = json.Marshal(f32) // ERROR "Error return value of `encoding/json.Marshal` is not checked: unsafe type `float32` found"
_, err = json.Marshal(f32) // err is checked
_ = err
Expand Down Expand Up @@ -516,6 +517,7 @@ func JSONMarshalInvalidTypes() {
var err error

var c64 complex64
json.Marshal(c64) // ERROR "`encoding/json.Marshal` for unsupported type `complex64` found"
_, _ = json.Marshal(c64) // ERROR "`encoding/json.Marshal` for unsupported type `complex64` found"
_, err = json.Marshal(c64) // ERROR "`encoding/json.Marshal` for unsupported type `complex64` found"
_ = err
Expand Down
27 changes: 27 additions & 0 deletions test/testdata/errchkjson_omit_safe.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ func JSONMarshalUnsafeTypes() {
var err error

var f32 float32
json.Marshal(f32) // ERROR "Error return value of `encoding/json.Marshal` is not checked: unsafe type `float32` found"
_, _ = json.Marshal(f32) // ERROR "Error return value of `encoding/json.Marshal` is not checked: unsafe type `float32` found"
_, err = json.Marshal(f32) // err is checked
_ = err
Expand Down Expand Up @@ -516,6 +517,7 @@ func JSONMarshalInvalidTypes() {
var err error

var c64 complex64
json.Marshal(c64) // ERROR "`encoding/json.Marshal` for unsupported type `complex64` found"
_, _ = json.Marshal(c64) // ERROR "`encoding/json.Marshal` for unsupported type `complex64` found"
_, err = json.Marshal(c64) // ERROR "`encoding/json.Marshal` for unsupported type `complex64` found"
_ = err
Expand Down Expand Up @@ -612,3 +614,28 @@ func NotJSONMarshal() {
f := func() bool { return false }
_ = f()
}

// JSONMarshalStructWithoutExportedFields contains a struct without exported fields.
func JSONMarshalStructWithoutExportedFields() {
var err error

var withoutExportedFields struct {
privateField bool
ExportedButOmittedField bool `json:"-"`
}
_, err = json.Marshal(withoutExportedFields) // want "Error argument passed to `encoding/json.Marshal` does not contain any exported field"
_ = err
}

// JSONMarshalStructWithoutExportedFields contains a struct without exported fields.
func JSONMarshalStructWithNestedStructWithoutExportedFields() {
var err error

var withNestedStructWithoutExportedFields struct {
ExportedStruct struct {
privatField bool
}
}
_, err = json.Marshal(withNestedStructWithoutExportedFields)
_ = err
}

0 comments on commit 4c161ac

Please sign in to comment.