Skip to content

Commit 4c161ac

Browse files
committed
Update errchkjson to v0.1.1
1 parent 77a07b2 commit 4c161ac

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ require (
1616
github.com/blizzy78/varnamelen v0.4.0
1717
github.com/bombsimon/wsl/v3 v3.3.0
1818
github.com/breml/bidichk v0.1.1
19-
github.com/breml/errchkjson v0.1.0
19+
github.com/breml/errchkjson v0.1.1
2020
github.com/butuzov/ireturn v0.1.1
2121
github.com/charithe/durationcheck v0.0.9
2222
github.com/daixiang0/gci v0.2.9

go.sum

+2-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
@@ -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

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)