Skip to content

Commit 228fb75

Browse files
committed
Update errchkjson to v0.2.0
1 parent 0607414 commit 228fb75

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

go.sum

-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/testdata/errchkjson.go

+2
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ func JSONMarshalUnsafeTypes() {
394394
var err error
395395

396396
var f32 float32
397+
json.Marshal(f32) // ERROR "Error return value of `encoding/json.Marshal` is not checked: unsafe type `float32` found"
397398
_, _ = json.Marshal(f32) // ERROR "Error return value of `encoding/json.Marshal` is not checked: unsafe type `float32` found"
398399
_, err = json.Marshal(f32) // err is checked
399400
_ = err
@@ -517,6 +518,7 @@ func JSONMarshalInvalidTypes() {
517518
var err error
518519

519520
var c64 complex64
521+
json.Marshal(c64) // ERROR "`encoding/json.Marshal` for unsupported type `complex64` found"
520522
_, _ = json.Marshal(c64) // ERROR "`encoding/json.Marshal` for unsupported type `complex64` found"
521523
_, err = json.Marshal(c64) // ERROR "`encoding/json.Marshal` for unsupported type `complex64` found"
522524
_ = err

test/testdata/errchkjson_omit_safe.go

+27
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ func JSONMarshalUnsafeTypes() {
393393
var err error
394394

395395
var f32 float32
396+
json.Marshal(f32) // ERROR "Error return value of `encoding/json.Marshal` is not checked: unsafe type `float32` found"
396397
_, _ = json.Marshal(f32) // ERROR "Error return value of `encoding/json.Marshal` is not checked: unsafe type `float32` found"
397398
_, err = json.Marshal(f32) // err is checked
398399
_ = err
@@ -516,6 +517,7 @@ func JSONMarshalInvalidTypes() {
516517
var err error
517518

518519
var c64 complex64
520+
json.Marshal(c64) // ERROR "`encoding/json.Marshal` for unsupported type `complex64` found"
519521
_, _ = json.Marshal(c64) // ERROR "`encoding/json.Marshal` for unsupported type `complex64` found"
520522
_, err = json.Marshal(c64) // ERROR "`encoding/json.Marshal` for unsupported type `complex64` found"
521523
_ = err
@@ -612,3 +614,28 @@ func NotJSONMarshal() {
612614
f := func() bool { return false }
613615
_ = f()
614616
}
617+
618+
// JSONMarshalStructWithoutExportedFields contains a struct without exported fields.
619+
func JSONMarshalStructWithoutExportedFields() {
620+
var err error
621+
622+
var withoutExportedFields struct {
623+
privateField bool
624+
ExportedButOmittedField bool `json:"-"`
625+
}
626+
_, err = json.Marshal(withoutExportedFields) // want "Error argument passed to `encoding/json.Marshal` does not contain any exported field"
627+
_ = err
628+
}
629+
630+
// JSONMarshalStructWithoutExportedFields contains a struct without exported fields.
631+
func JSONMarshalStructWithNestedStructWithoutExportedFields() {
632+
var err error
633+
634+
var withNestedStructWithoutExportedFields struct {
635+
ExportedStruct struct {
636+
privatField bool
637+
}
638+
}
639+
_, err = json.Marshal(withNestedStructWithoutExportedFields)
640+
_ = err
641+
}

0 commit comments

Comments
 (0)