Skip to content

Commit 77a07b2

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 613a95c commit 77a07b2

File tree

3 files changed

+71
-72
lines changed

3 files changed

+71
-72
lines changed

pkg/golinters/errchkjson.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
package golinters
22

33
import (
4-
"golang.org/x/tools/go/analysis"
5-
64
"github.com/breml/errchkjson"
5+
"golang.org/x/tools/go/analysis"
76

87
"github.com/golangci/golangci-lint/pkg/config"
98
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"

test/testdata/errchkjson.go

+36-36
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-
// JSONMarshalSaveTypes 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 JSONMarshalSaveTypes() {
21+
// JSONMarshalSafeTypes 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 JSONMarshalSafeTypes() {
2424
var err error
2525

2626
_, _ = json.Marshal(nil) // nil is safe
@@ -253,7 +253,7 @@ func JSONMarshalSaveTypes() {
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
@@ -351,45 +351,45 @@ func JSONMarshalSaveStructWithUnexportedFields() {
351351
func JSONMarshalSaveStructWithOmittedFields() {
352352
var err error
353353

354-
var ommitInStruct struct {
354+
var omitInStruct 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
}
384-
_ = ommitInStruct.MapStructStr[structKey{1}]
385-
_, _ = json.Marshal(ommitInStruct) // struct containing unsafe but omitted, exported fields is safe
386-
_, err = json.Marshal(ommitInStruct) // ERROR "Error return value of `encoding/json.Marshal` is checked but passed argument is safe"
384+
_ = omitInStruct.MapStructStr[structKey{1}]
385+
_, _ = json.Marshal(omitInStruct) // struct containing unsafe but omitted, exported fields is safe
386+
_, err = json.Marshal(omitInStruct) // ERROR "Error return value of `encoding/json.Marshal` is checked but passed argument is safe"
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

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)