Skip to content

Commit 25f382c

Browse files
committed
all: fix linter suggestions
1 parent ca4afad commit 25f382c

File tree

6 files changed

+21
-3
lines changed

6 files changed

+21
-3
lines changed

errors.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ func (e *Error) Error() string {
3131
if e == nil {
3232
return ""
3333
}
34+
3435
return e.Message
3536
}
3637

handler.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ func (EmptyHandler) Deliver(ctx context.Context, r *Request, delivered bool) boo
8989
return false
9090
}
9191
}
92+
9293
return true
9394
}
9495

jsonrpc2.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ func (c *Conn) Call(ctx context.Context, method string, params, result interface
204204
if err := json.Unmarshal(*resp.Result, result); err != nil {
205205
return fmt.Errorf("failed to unmarshalling result: %v", err)
206206
}
207+
207208
return nil
208209

209210
case <-ctx.Done():
@@ -214,6 +215,7 @@ func (c *Conn) Call(ctx context.Context, method string, params, result interface
214215
canceled = true
215216
}
216217
}
218+
217219
return ctx.Err()
218220
}
219221
}
@@ -258,6 +260,7 @@ func (c *Conn) Run(ctx context.Context) error {
258260
for _, h := range c.handlers {
259261
h.Error(ctx, errMsg)
260262
}
263+
261264
continue
262265
}
263266

jsonrpc2_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ func (test *callTest) newResults() interface{} {
5858
for _, v := range e {
5959
r = append(r, reflect.New(reflect.TypeOf(v)).Interface())
6060
}
61+
6162
return r
6263
case nil:
6364
return nil
@@ -81,6 +82,7 @@ func prepare(ctx context.Context, t *testing.T) (a, b *jsonrpc2.Conn) {
8182
bR, aW := io.Pipe()
8283
a = run(ctx, t, aR, aW)
8384
b = run(ctx, t, bR, bW)
85+
8486
return a, b
8587
}
8688

@@ -139,6 +141,7 @@ func (h handle) Deliver(ctx context.Context, r *jsonrpc2.Request, delivered bool
139141
case "no_args":
140142
if r.Params != nil {
141143
r.Reply(ctx, nil, jsonrpc2.Errorf(jsonrpc2.InvalidParams, "Expected no params"))
144+
142145
return true
143146
}
144147
r.Reply(ctx, true, nil)
@@ -147,6 +150,7 @@ func (h handle) Deliver(ctx context.Context, r *jsonrpc2.Request, delivered bool
147150
var v string
148151
if err := json.Unmarshal(*r.Params, &v); err != nil {
149152
r.Reply(ctx, nil, jsonrpc2.Errorf(jsonrpc2.ParseError, "%v", err.Error()))
153+
150154
return true
151155
}
152156
r.Reply(ctx, "got:"+v, nil)
@@ -155,6 +159,7 @@ func (h handle) Deliver(ctx context.Context, r *jsonrpc2.Request, delivered bool
155159
var v int
156160
if err := json.Unmarshal(*r.Params, &v); err != nil {
157161
r.Reply(ctx, nil, jsonrpc2.Errorf(jsonrpc2.ParseError, "%v", err.Error()))
162+
158163
return true
159164
}
160165
r.Reply(ctx, fmt.Sprintf("got:%d", v), nil)
@@ -163,6 +168,7 @@ func (h handle) Deliver(ctx context.Context, r *jsonrpc2.Request, delivered bool
163168
var v []string
164169
if err := json.Unmarshal(*r.Params, &v); err != nil {
165170
r.Reply(ctx, nil, jsonrpc2.Errorf(jsonrpc2.ParseError, "%v", err.Error()))
171+
166172
return true
167173
}
168174
r.Reply(ctx, path.Join(v...), nil)
@@ -193,6 +199,7 @@ func (h handle) Request(ctx context.Context, conn *jsonrpc2.Conn, direction json
193199
ctx = context.WithValue(ctx, ctxMethodKey{}, r.Method)
194200
ctx = context.WithValue(ctx, ctxTimeKey{}, time.Now())
195201
}
202+
196203
return ctx
197204
}
198205

@@ -202,6 +209,7 @@ func (h handle) Response(ctx context.Context, conn *jsonrpc2.Conn, direction jso
202209
elapsed := time.Since(ctx.Value(ctxTimeKey{}).(time.Time))
203210
h.logger.Info("Response", zap.String(method.(string), fmt.Sprintf("%v response in %v [%v] %s %v", direction, elapsed, r.ID, method, r.Result)))
204211
}
212+
205213
return ctx
206214
}
207215

stream_bench_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
package jsonrpc2
5+
package jsonrpc2_test
66

77
import (
88
"bytes"
99
"context"
1010
"io/ioutil"
1111
"testing"
12+
13+
"go.lsp.dev/jsonrpc2"
1214
)
1315

1416
const payload = `Content-Length: 265
@@ -41,7 +43,7 @@ func BenchmarkSteam_Read(b *testing.B) {
4143
b.ResetTimer()
4244
for i := 0; i < b.N; i++ {
4345
in.Write([]byte(payload))
44-
stream := NewStream(&in, ioutil.Discard)
46+
stream := jsonrpc2.NewStream(&in, ioutil.Discard)
4547
_, _, _ = stream.Read(context.Background())
4648
in.Reset()
4749
}
@@ -52,7 +54,7 @@ func BenchmarkSteam_Write(b *testing.B) {
5254
b.ReportAllocs()
5355
b.ResetTimer()
5456
for i := 0; i < b.N; i++ {
55-
stream := NewStream(nil, ioutil.Discard)
57+
stream := jsonrpc2.NewStream(nil, ioutil.Discard)
5658
_, _ = stream.Write(context.Background(), []byte(payload))
5759
}
5860
b.SetBytes(int64(len(payload)))

types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ func (version) UnmarshalJSON(data []byte) error {
3030
if version != Version {
3131
return fmt.Errorf("invalid JSON-RPC version %v", version)
3232
}
33+
3334
return nil
3435
}
3536

@@ -69,6 +70,7 @@ func (id *ID) MarshalJSON() ([]byte, error) {
6970
if id.name != "" {
7071
return json.Marshal(id.name)
7172
}
73+
7274
return json.Marshal(id.number)
7375
}
7476

@@ -78,6 +80,7 @@ func (id *ID) UnmarshalJSON(data []byte) error {
7880
if err := json.Unmarshal(data, &id.number); err == nil {
7981
return nil
8082
}
83+
8184
return json.Unmarshal(data, &id.name)
8285
}
8386

0 commit comments

Comments
 (0)