summaryrefslogtreecommitdiff
path: root/compat
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@datawire.io>2022-08-17 19:57:00 -0600
committerLuke Shumaker <lukeshu@datawire.io>2022-08-17 19:57:00 -0600
commit3bd2e0e93647b806a68f06f319ea23511ec24a37 (patch)
tree0c0f56296d0fe49e34e23d7738aed4dd60ca32e1 /compat
parentb2bf19e062ad1ce46dbf9107f5c3b47354f64d03 (diff)
Get the borrowed files passing the linter
Diffstat (limited to 'compat')
-rw-r--r--compat/json/borrowed_bench_test.go4
-rw-r--r--compat/json/borrowed_decode_test.go30
-rw-r--r--compat/json/borrowed_stream_test.go16
-rw-r--r--compat/json/borrowed_tagkey_test.go5
4 files changed, 32 insertions, 23 deletions
diff --git a/compat/json/borrowed_bench_test.go b/compat/json/borrowed_bench_test.go
index f5595ff..0155ff9 100644
--- a/compat/json/borrowed_bench_test.go
+++ b/compat/json/borrowed_bench_test.go
@@ -177,7 +177,9 @@ func BenchmarkUnicodeDecoder(b *testing.B) {
if err := dec.Decode(&out); err != nil {
b.Fatal("Decode:", err)
}
- r.Seek(0, 0)
+ if _, err := r.Seek(0, 0); err != nil { // MODIFIED: check the error
+ b.Fatal("Seek:", err) // MODIFIED: added
+ } // MODIFIED: added
}
}
diff --git a/compat/json/borrowed_decode_test.go b/compat/json/borrowed_decode_test.go
index 2c89d5d..dd9c344 100644
--- a/compat/json/borrowed_decode_test.go
+++ b/compat/json/borrowed_decode_test.go
@@ -77,7 +77,7 @@ var ifaceNumAsNumber = map[string]any{
}
type tx struct {
- x int
+ x int //nolint:unused // it is used, but only via reflection // MODIFIED: added nolint annotation
}
type u8 uint8
@@ -421,11 +421,11 @@ var unmarshalTests = []unmarshalTest{
{in: `"g-clef: \uD834\uDD1E"`, ptr: new(string), out: "g-clef: \U0001D11E"},
{in: `"invalid: \uD834x\uDD1E"`, ptr: new(string), out: "invalid: \uFFFDx\uFFFD"},
{in: "null", ptr: new(any), out: nil},
- {in: `{"X": [1,2,3], "Y": 4}`, ptr: new(T), out: T{Y: 4}, err: &UnmarshalTypeError{"array", reflect.TypeOf(""), 7, "T", "X"}},
- {in: `{"X": 23}`, ptr: new(T), out: T{}, err: &UnmarshalTypeError{"number", reflect.TypeOf(""), 8, "T", "X"}}, {in: `{"x": 1}`, ptr: new(tx), out: tx{}},
+ {in: `{"X": [1,2,3], "Y": 4}`, ptr: new(T), out: T{Y: 4}, err: &UnmarshalTypeError{Value: "array", Type: reflect.TypeOf(""), Offset: 7, Struct: "T", Field: "X"}}, // MODIFIED: don't use unkeyed fields (govet)
+ {in: `{"X": 23}`, ptr: new(T), out: T{}, err: &UnmarshalTypeError{Value: "number", Type: reflect.TypeOf(""), Offset: 8, Struct: "T", Field: "X"}}, {in: `{"x": 1}`, ptr: new(tx), out: tx{}}, // MODIFIED: don't use unkeyed fields (govet)
{in: `{"x": 1}`, ptr: new(tx), out: tx{}},
{in: `{"x": 1}`, ptr: new(tx), err: fmt.Errorf("json: unknown field \"x\""), disallowUnknownFields: true},
- {in: `{"S": 23}`, ptr: new(W), out: W{}, err: &UnmarshalTypeError{"number", reflect.TypeOf(SS("")), 0, "W", "S"}},
+ {in: `{"S": 23}`, ptr: new(W), out: W{}, err: &UnmarshalTypeError{Value: "number", Type: reflect.TypeOf(SS("")), Offset: 0, Struct: "W", Field: "S"}}, // MODIFIED: don't use unkeyed fields (govet)
{in: `{"F1":1,"F2":2,"F3":3}`, ptr: new(V), out: V{F1: float64(1), F2: int32(2), F3: Number("3")}},
{in: `{"F1":1,"F2":2,"F3":3}`, ptr: new(V), out: V{F1: Number("1"), F2: int32(2), F3: Number("3")}, useNumber: true},
{in: `{"k1":1,"k2":"s","k3":[1,2.0,3e-3],"k4":{"kk1":"s","kk2":2}}`, ptr: new(any), out: ifaceNumAsFloat64},
@@ -1342,7 +1342,7 @@ type All struct {
Float64 float64
Foo string `json:"bar"`
- Foo2 string `json:"bar2,dummyopt"`
+ Foo2 string `json:"bar2,dummyopt"` //nolint:staticcheck // testing handling of unknown options // MODIFIED: added nolint annotation
IntStr int64 `json:",string"`
UintptrStr uintptr `json:",string"`
@@ -1391,7 +1391,7 @@ type All struct {
Interface any
PInterface *any
- unexported int
+ unexported int //nolint:unused // it is used, but only via reflection // MODIFIED: added nolint annotation
}
type Small struct {
@@ -2047,10 +2047,10 @@ func TestUnmarshalSyntax(t *testing.T) {
// Issue 4660
type unexportedFields struct {
Name string
- m map[string]any `json:"-"`
- m2 map[string]any `json:"abcd"`
+ m map[string]any `json:"-"` //nolint:unused,govet // testing handling of unused fields // MODIFIED: added nolint annotation
+ m2 map[string]any `json:"abcd"` //nolint:unused // testing handling of unused fields // MODIFIED: added nolint annotation
- s []int `json:"-"`
+ s []int `json:"-"` //nolint:unused // testing handling of unused fields // MODIFIED: added nolint annotation
}
func TestUnmarshalUnexported(t *testing.T) {
@@ -2213,11 +2213,11 @@ func TestInvalidUnmarshalText(t *testing.T) {
func TestInvalidStringOption(t *testing.T) {
num := 0
item := struct {
- T time.Time `json:",string"`
- M map[string]string `json:",string"`
- S []string `json:",string"`
- A [1]string `json:",string"`
- I any `json:",string"`
+ T time.Time `json:",string"` //nolint:staticcheck // testing handling of bad options // MODIFIED: added nolint annotation
+ M map[string]string `json:",string"` //nolint:staticcheck // testing handling of bad options // MODIFIED: added nolint annotation
+ S []string `json:",string"` //nolint:staticcheck // testing handling of bad options // MODIFIED: added nolint annotation
+ A [1]string `json:",string"` //nolint:staticcheck // testing handling of bad options // MODIFIED: added nolint annotation
+ I any `json:",string"` //nolint:staticcheck // testing handling of bad options // MODIFIED: added nolint annotation
P *int `json:",string"`
}{M: make(map[string]string), S: make([]string, 0), I: num, P: &num}
@@ -2408,7 +2408,7 @@ func TestUnmarshalPanic(t *testing.T) {
t.Errorf("panic() = (%T)(%v), want 0xdead", got, got)
}
}()
- Unmarshal([]byte("{}"), &unmarshalPanic{})
+ _ = Unmarshal([]byte("{}"), &unmarshalPanic{}) // MODIFIED: added the _ dogsled for the linter
t.Fatalf("Unmarshal should have panicked")
}
diff --git a/compat/json/borrowed_stream_test.go b/compat/json/borrowed_stream_test.go
index 658e347..edeab4a 100644
--- a/compat/json/borrowed_stream_test.go
+++ b/compat/json/borrowed_stream_test.go
@@ -81,7 +81,9 @@ func TestEncoderIndent(t *testing.T) {
enc := NewEncoder(&buf)
enc.SetIndent(">", ".")
for _, v := range streamTest {
- enc.Encode(v)
+ if err := enc.Encode(v); err != nil { // MODIFIED: check the error
+ t.Error("Encode:", err) // MODIFIED: added
+ } // MODIFIED: added
}
if have, want := buf.String(), streamEncodedIndent; have != want {
t.Error("indented encoding mismatch")
@@ -106,7 +108,7 @@ func TestEncoderSetEscapeHTML(t *testing.T) {
var ct CText
var tagStruct struct {
Valid int `json:"<>&#! "`
- Invalid int `json:"\\"`
+ Invalid int `json:"\\"` //nolint:staticcheck // testing handling of bad tags // MODIFIED: added nolint annotation
}
// This case is particularly interesting, as we force the encoder to
@@ -296,7 +298,8 @@ var blockingTests = []string{
func TestBlocking(t *testing.T) {
for _, enc := range blockingTests {
r, w := net.Pipe()
- go w.Write([]byte(enc))
+ ch := make(chan error) // MODIFIED: added
+ go func() { _, err := w.Write([]byte(enc)); ch <- err }() // MODIFIED: check the error
var val any
// If Decode reads beyond what w.Write writes above,
@@ -305,6 +308,9 @@ func TestBlocking(t *testing.T) {
t.Errorf("decoding %s: %v", enc, err)
}
r.Close()
+ if err := <-ch; err != nil { // MODIFIED: added
+ t.Error(err) // MODIFIED: added
+ } // MODIFIED: added
w.Close()
}
}
@@ -324,6 +330,7 @@ func BenchmarkEncoderEncode(b *testing.B) {
})
}
+/* // MODIFIED: we don't have tokens
type tokenStreamCase struct {
json string
expTokens []any
@@ -333,7 +340,6 @@ type decodeThis struct {
v any
}
-/* // MODIFIED: we don't have tokens
var tokenStreamCases = []tokenStreamCase{
// streaming token cases
{json: `10`, expTokens: []any{float64(10)}},
@@ -446,7 +452,7 @@ func TestHTTPDecoding(t *testing.T) {
const raw = `{ "foo": "bar" }`
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- w.Write([]byte(raw))
+ _, _ = w.Write([]byte(raw)) // MODIFIED: added the _, _ dogsled for the linter
}))
defer ts.Close()
res, err := http.Get(ts.URL)
diff --git a/compat/json/borrowed_tagkey_test.go b/compat/json/borrowed_tagkey_test.go
index 6330efd..59e4061 100644
--- a/compat/json/borrowed_tagkey_test.go
+++ b/compat/json/borrowed_tagkey_test.go
@@ -41,6 +41,7 @@ type percentSlashTag struct {
}
type punctuationTag struct {
+ //nolint:staticcheck // testing handling of bad tags // MODIFIED: added nolint annotation
V string `json:"!#$%&()*+-./:;<=>?@[]^_{|}~ "` // https://golang.org/issue/3546
}
@@ -57,11 +58,11 @@ type misnamedTag struct {
}
type badFormatTag struct {
- Y string `:"BadFormat"`
+ Y string `:"BadFormat"` //nolint:govet // testing handling of bad tags // MODIFIED: added nolint annotation
}
type badCodeTag struct {
- Z string `json:" !\"#&'()*+,."`
+ Z string `json:" !\"#&'()*+,."` //nolint:staticcheck // testing handling of bad tags // MODIFIED: added nolint annotation
}
type spaceTag struct {