Skip to content

Commit 0607414

Browse files
bremlldez
andcommitted
Fix typo, order imports
Update pkg/golinters/errchkjson.go Update test/testdata/errchkjson.go Update test/testdata/errchkjson_omit_safe.go Co-authored-by: Ludovic Fernandez <[email protected]>
1 parent 869c2ff commit 0607414

File tree

2 files changed

+70
-70
lines changed

2 files changed

+70
-70
lines changed

test/testdata/errchkjson.go

+36-36
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ func (mt marshalText) MarshalText() ([]byte, error) {
1919

2020
var _ encoding.TextMarshaler = marshalText(struct{}{})
2121

22-
// JSONMarshalSaveTypes contains a multitude of test cases to marshal different combinations of types to JSON,
23-
// that are save, that is, they will never return an error, if these types are marshaled to JSON.
24-
func JSONMarshalSaveTypes() {
22+
// JSONMarshalSafeTypes contains a multitude of test cases to marshal different combinations of types to JSON,
23+
// that are safe, that is, they will never return an error, if these types are marshaled to JSON.
24+
func JSONMarshalSafeTypes() {
2525
var err error
2626

2727
_, _ = json.Marshal(nil) // nil is safe
@@ -254,7 +254,7 @@ func JSONMarshalSaveTypes() {
254254

255255
type (
256256
structKey struct{ id int }
257-
ExportedUnsafeAndInvalidStruct struct { // unsafe unexported but ommited
257+
ExportedUnsafeAndInvalidStruct struct { // unsafe unexported but omitted
258258
F64 float64
259259
F64Ptr *float64
260260
F64Slice []float64
@@ -352,45 +352,45 @@ func JSONMarshalSaveStructWithUnexportedFields() {
352352
func JSONMarshalSaveStructWithOmittedFields() {
353353
var err error
354354

355-
var ommitInStruct struct {
355+
var omitInStruct struct {
356356
Bool bool // safe exported
357357

358-
F64 float64 `json:"-"` // unsafe exported but ommited
359-
F64Ptr *float64 `json:"-"` // unsafe exported but ommited
360-
F64Slice []float64 `json:"-"` // unsafe exported but ommited
361-
F64Array [10]float64 `json:"-"` // unsafe exported but ommited
362-
MapStrF64 map[string]float64 `json:"-"` // unsafe exported but ommited
363-
MapEIStr map[interface{}]string `json:"-"` // unsafe exported but ommited
364-
Number json.Number `json:"-"` // unsafe exported but ommited
365-
NumberPtr *json.Number `json:"-"` // unsafe exported but ommited
366-
NumberSlice []json.Number `json:"-"` // unsafe exported but ommited
367-
MapNumberStr map[json.Number]string `json:"-"` // unsafe exported but ommited
368-
Ei interface{} `json:"-"` // unsafe exported but ommited
369-
Stringer fmt.Stringer `json:"-"` // unsafe exported but ommited
370-
Mt marshalText `json:"-"` // unsafe exported but ommited
371-
MapMarshalTextString map[marshalText]string `json:"-"` // unsafe exported but ommited
372-
ExportedStruct ExportedUnsafeAndInvalidStruct `json:"-"` // unsafe exported but ommited
373-
ExportedStructPtr *ExportedUnsafeAndInvalidStruct `json:"-"` // unsafe exported but ommited
374-
375-
C128 complex128 `json:"-"` // invalid exported but ommited
376-
C128Slice []complex128 `json:"-"` // invalid exported but ommited
377-
C128Array [10]complex128 `json:"-"` // invalid exported but ommited
378-
MapBoolStr map[bool]string `json:"-"` // invalid exported but ommited
379-
MapF64Str map[float64]string `json:"-"` // invalid exported but ommited
380-
F func() `json:"-"` // invalid exported but ommited
381-
Ch chan struct{} `json:"-"` // invalid exported but ommited
382-
UnsafePtr unsafe.Pointer `json:"-"` // invalid exported but ommited
383-
MapStructStr map[structKey]string `json:"-"` // invalid exported but ommited
358+
F64 float64 `json:"-"` // unsafe exported but omitted
359+
F64Ptr *float64 `json:"-"` // unsafe exported but omitted
360+
F64Slice []float64 `json:"-"` // unsafe exported but omitted
361+
F64Array [10]float64 `json:"-"` // unsafe exported but omitted
362+
MapStrF64 map[string]float64 `json:"-"` // unsafe exported but omitted
363+
MapEIStr map[interface{}]string `json:"-"` // unsafe exported but omitted
364+
Number json.Number `json:"-"` // unsafe exported but omitted
365+
NumberPtr *json.Number `json:"-"` // unsafe exported but omitted
366+
NumberSlice []json.Number `json:"-"` // unsafe exported but omitted
367+
MapNumberStr map[json.Number]string `json:"-"` // unsafe exported but omitted
368+
Ei interface{} `json:"-"` // unsafe exported but omitted
369+
Stringer fmt.Stringer `json:"-"` // unsafe exported but omitted
370+
Mt marshalText `json:"-"` // unsafe exported but omitted
371+
MapMarshalTextString map[marshalText]string `json:"-"` // unsafe exported but omitted
372+
ExportedStruct ExportedUnsafeAndInvalidStruct `json:"-"` // unsafe exported but omitted
373+
ExportedStructPtr *ExportedUnsafeAndInvalidStruct `json:"-"` // unsafe exported but omitted
374+
375+
C128 complex128 `json:"-"` // invalid exported but omitted
376+
C128Slice []complex128 `json:"-"` // invalid exported but omitted
377+
C128Array [10]complex128 `json:"-"` // invalid exported but omitted
378+
MapBoolStr map[bool]string `json:"-"` // invalid exported but omitted
379+
MapF64Str map[float64]string `json:"-"` // invalid exported but omitted
380+
F func() `json:"-"` // invalid exported but omitted
381+
Ch chan struct{} `json:"-"` // invalid exported but omitted
382+
UnsafePtr unsafe.Pointer `json:"-"` // invalid exported but omitted
383+
MapStructStr map[structKey]string `json:"-"` // invalid exported but omitted
384384
}
385-
_ = ommitInStruct.MapStructStr[structKey{1}]
386-
_, _ = json.Marshal(ommitInStruct) // struct containing unsafe but omitted, exported fields is safe
387-
_, err = json.Marshal(ommitInStruct) // ERROR "Error return value of `encoding/json.Marshal` is checked but passed argument is safe"
385+
_ = omitInStruct.MapStructStr[structKey{1}]
386+
_, _ = json.Marshal(omitInStruct) // struct containing unsafe but omitted, exported fields is safe
387+
_, err = json.Marshal(omitInStruct) // ERROR "Error return value of `encoding/json.Marshal` is checked but passed argument is safe"
388388
_ = err
389389
}
390390

391-
// JSONMarshalUnsaveTypes contains a multitude of test cases to marshal different combinations of types to JSON,
391+
// JSONMarshalUnsafeTypes contains a multitude of test cases to marshal different combinations of types to JSON,
392392
// that can potentially lead to json.Marshal returning an error.
393-
func JSONMarshalUnsaveTypes() {
393+
func JSONMarshalUnsafeTypes() {
394394
var err error
395395

396396
var f32 float32

test/testdata/errchkjson_omit_safe.go

+34-34
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ func (mt marshalText) MarshalText() ([]byte, error) {
1818

1919
var _ encoding.TextMarshaler = marshalText(struct{}{})
2020

21-
// JSONMarshalSaveTypesWithNoSafe contains a multitude of test cases to marshal different combinations of types to JSON,
22-
// that are save, that is, they will never return an error, if these types are marshaled to JSON.
23-
func JSONMarshalSaveTypesWithNoSafe() {
21+
// JSONMarshalSafeTypesWithNoSafe contains a multitude of test cases to marshal different combinations of types to JSON,
22+
// that are safe, that is, they will never return an error, if these types are marshaled to JSON.
23+
func JSONMarshalSafeTypesWithNoSafe() {
2424
var err error
2525

2626
_, _ = json.Marshal(nil) // ERROR "Error return value of `encoding/json.Marshal` is not checked"
@@ -253,7 +253,7 @@ func JSONMarshalSaveTypesWithNoSafe() {
253253

254254
type (
255255
structKey struct{ id int }
256-
ExportedUnsafeAndInvalidStruct struct { // unsafe unexported but ommited
256+
ExportedUnsafeAndInvalidStruct struct { // unsafe unexported but omitted
257257
F64 float64
258258
F64Ptr *float64
259259
F64Slice []float64
@@ -282,7 +282,7 @@ type (
282282
}
283283
)
284284

285-
// JSONMarshalSaveStructWithUnexportedFields contains a struct with unexported, unsafe fields.
285+
// JSONMarshalSafeStructWithUnexportedFieldsWithNoSafe contains a struct with unexported, unsafe fields.
286286
func JSONMarshalSaveStructWithUnexportedFieldsWithNoSafe() {
287287
var err error
288288

@@ -347,49 +347,49 @@ func JSONMarshalSaveStructWithUnexportedFieldsWithNoSafe() {
347347
_ = err
348348
}
349349

350-
// JSONMarshalSaveStructWithOmittedFields contains a struct with omitted, unsafe fields.
350+
// JSONMarshalSafeStructWithOmittedFieldsWithNoSafe contains a struct with omitted, unsafe fields.
351351
func JSONMarshalSaveStructWithOmittedFieldsWithNoSafe() {
352352
var err error
353353

354354
var ommitInStruct struct {
355355
Bool bool // safe exported
356356

357-
F64 float64 `json:"-"` // unsafe exported but ommited
358-
F64Ptr *float64 `json:"-"` // unsafe exported but ommited
359-
F64Slice []float64 `json:"-"` // unsafe exported but ommited
360-
F64Array [10]float64 `json:"-"` // unsafe exported but ommited
361-
MapStrF64 map[string]float64 `json:"-"` // unsafe exported but ommited
362-
MapEIStr map[interface{}]string `json:"-"` // unsafe exported but ommited
363-
Number json.Number `json:"-"` // unsafe exported but ommited
364-
NumberPtr *json.Number `json:"-"` // unsafe exported but ommited
365-
NumberSlice []json.Number `json:"-"` // unsafe exported but ommited
366-
MapNumberStr map[json.Number]string `json:"-"` // unsafe exported but ommited
367-
Ei interface{} `json:"-"` // unsafe exported but ommited
368-
Stringer fmt.Stringer `json:"-"` // unsafe exported but ommited
369-
Mt marshalText `json:"-"` // unsafe exported but ommited
370-
MapMarshalTextString map[marshalText]string `json:"-"` // unsafe exported but ommited
371-
ExportedStruct ExportedUnsafeAndInvalidStruct `json:"-"` // unsafe exported but ommited
372-
ExportedStructPtr *ExportedUnsafeAndInvalidStruct `json:"-"` // unsafe exported but ommited
373-
374-
C128 complex128 `json:"-"` // invalid exported but ommited
375-
C128Slice []complex128 `json:"-"` // invalid exported but ommited
376-
C128Array [10]complex128 `json:"-"` // invalid exported but ommited
377-
MapBoolStr map[bool]string `json:"-"` // invalid exported but ommited
378-
MapF64Str map[float64]string `json:"-"` // invalid exported but ommited
379-
F func() `json:"-"` // invalid exported but ommited
380-
Ch chan struct{} `json:"-"` // invalid exported but ommited
381-
UnsafePtr unsafe.Pointer `json:"-"` // invalid exported but ommited
382-
MapStructStr map[structKey]string `json:"-"` // invalid exported but ommited
357+
F64 float64 `json:"-"` // unsafe exported but omitted
358+
F64Ptr *float64 `json:"-"` // unsafe exported but omitted
359+
F64Slice []float64 `json:"-"` // unsafe exported but omitted
360+
F64Array [10]float64 `json:"-"` // unsafe exported but omitted
361+
MapStrF64 map[string]float64 `json:"-"` // unsafe exported but omitted
362+
MapEIStr map[interface{}]string `json:"-"` // unsafe exported but omitted
363+
Number json.Number `json:"-"` // unsafe exported but omitted
364+
NumberPtr *json.Number `json:"-"` // unsafe exported but omitted
365+
NumberSlice []json.Number `json:"-"` // unsafe exported but omitted
366+
MapNumberStr map[json.Number]string `json:"-"` // unsafe exported but omitted
367+
Ei interface{} `json:"-"` // unsafe exported but omitted
368+
Stringer fmt.Stringer `json:"-"` // unsafe exported but omitted
369+
Mt marshalText `json:"-"` // unsafe exported but omitted
370+
MapMarshalTextString map[marshalText]string `json:"-"` // unsafe exported but omitted
371+
ExportedStruct ExportedUnsafeAndInvalidStruct `json:"-"` // unsafe exported but omitted
372+
ExportedStructPtr *ExportedUnsafeAndInvalidStruct `json:"-"` // unsafe exported but omitted
373+
374+
C128 complex128 `json:"-"` // invalid exported but omitted
375+
C128Slice []complex128 `json:"-"` // invalid exported but omitted
376+
C128Array [10]complex128 `json:"-"` // invalid exported but omitted
377+
MapBoolStr map[bool]string `json:"-"` // invalid exported but omitted
378+
MapF64Str map[float64]string `json:"-"` // invalid exported but omitted
379+
F func() `json:"-"` // invalid exported but omitted
380+
Ch chan struct{} `json:"-"` // invalid exported but omitted
381+
UnsafePtr unsafe.Pointer `json:"-"` // invalid exported but omitted
382+
MapStructStr map[structKey]string `json:"-"` // invalid exported but omitted
383383
}
384384
_ = ommitInStruct.MapStructStr[structKey{1}]
385385
_, _ = json.Marshal(ommitInStruct) // ERROR "Error return value of `encoding/json.Marshal` is not checked"
386386
_, err = json.Marshal(ommitInStruct) // struct containing unsafe but omitted, exported fields is safe, but omit-safe is set
387387
_ = err
388388
}
389389

390-
// JSONMarshalUnsaveTypes contains a multitude of test cases to marshal different combinations of types to JSON,
390+
// JSONMarshalUnsafeTypes contains a multitude of test cases to marshal different combinations of types to JSON,
391391
// that can potentially lead to json.Marshal returning an error.
392-
func JSONMarshalUnsaveTypes() {
392+
func JSONMarshalUnsafeTypes() {
393393
var err error
394394

395395
var f32 float32

0 commit comments

Comments
 (0)