Skip to content

Commit a000aed

Browse files
add linter wsl_v5 (#551)
wsl (whitespace linter) is a linter that wants you to use empty lines to separate grouping of different types to increase readability. There are also a few places where it encourages you to remove whitespaces which is at the start and the end of blocks or between assigning and error checking.
1 parent 85e7633 commit a000aed

29 files changed

+195
-3
lines changed

.golangci.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,13 @@ linters:
8585
- whitespace
8686
- zerologlint
8787
- tagalign
88+
- wsl_v5
8889
disable:
8990
- varnamelen
9091
- depguard
9192
- funlen
9293
- gochecknoglobals
9394
- godox
94-
- wsl
9595
- exhaustruct
9696
- err113
9797
- lll
@@ -119,4 +119,4 @@ formatters:
119119
golines:
120120
max-len: 120
121121
# Conflict with tagalign
122-
reformat-tags: false
122+
reformat-tags: false

commenter.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,12 @@ func (c *commenter) withComment(ctx context.Context, query string) string {
5858
}
5959

6060
var cc commentCarrier
61+
6162
c.propagator.Inject(ctx, &cc)
6263

6364
if len(cc) == 0 {
6465
return query
6566
}
67+
6668
return fmt.Sprintf("%s /*%s*/", query, cc.Marshal())
6769
}

commenter_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ func TestCommenter_WithComment(t *testing.T) {
3434
require.NoError(t, err)
3535
traceState, err := trace.ParseTraceState("rojo=00f067aa0ba902b7,congo=t61rcWkgMzE")
3636
require.NoError(t, err)
37+
3738
ctx := trace.ContextWithSpanContext(context.Background(), trace.NewSpanContext(trace.SpanContextConfig{
3839
TraceID: traceID,
3940
SpanID: spanID,
@@ -45,6 +46,7 @@ func TestCommenter_WithComment(t *testing.T) {
4546
require.NoError(t, err)
4647
b, err := baggage.New(m1)
4748
require.NoError(t, err)
49+
4850
ctx = baggage.ContextWithBaggage(ctx, b)
4951

5052
testCases := []struct {

config_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ func TestConfigSemConvStabilityOptIn(t *testing.T) {
114114

115115
// Test with a sample query to verify it returns the expected attributes format
116116
const query = "SELECT * FROM test"
117+
117118
attrs := cfg.DBQueryTextAttributes(query)
118119

119120
// Verify format of returned attributes based on opt-in type

conn.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,24 +57,29 @@ func (c *otConn) Ping(ctx context.Context) (err error) {
5757

5858
method := MethodConnPing
5959
onDefer := recordMetric(ctx, c.cfg.Instruments, c.cfg, method, "", nil)
60+
6061
defer func() {
6162
onDefer(err)
6263
}()
6364

6465
if c.cfg.SpanOptions.Ping {
6566
if filterSpan(ctx, c.cfg.SpanOptions, method, "", nil) {
6667
var span trace.Span
68+
6769
ctx, span = createSpan(ctx, c.cfg, method, false, "", nil)
70+
6871
defer func() {
6972
if err != nil {
7073
recordSpanError(span, c.cfg.SpanOptions, err)
7174
}
75+
7276
span.End()
7377
}()
7478
}
7579
}
7680

7781
err = pinger.Ping(ctx)
82+
7883
return err
7984
}
8085

@@ -83,6 +88,7 @@ func (c *otConn) Exec(query string, args []driver.Value) (driver.Result, error)
8388
if !ok {
8489
return nil, driver.ErrSkip
8590
}
91+
8692
return execer.Exec(query, args)
8793
}
8894

@@ -96,6 +102,7 @@ func (c *otConn) ExecContext(
96102

97103
method := MethodConnExec
98104
onDefer := recordMetric(ctx, c.cfg.Instruments, c.cfg, method, query, args)
105+
99106
defer func() {
100107
onDefer(err)
101108
}()
@@ -111,6 +118,7 @@ func (c *otConn) ExecContext(
111118
recordSpanError(span, c.cfg.SpanOptions, err)
112119
return nil, err
113120
}
121+
114122
return res, nil
115123
}
116124

@@ -119,6 +127,7 @@ func (c *otConn) Query(query string, args []driver.Value) (driver.Rows, error) {
119127
if !ok {
120128
return nil, driver.ErrSkip
121129
}
130+
122131
return queryer.Query(query, args)
123132
}
124133

@@ -132,11 +141,13 @@ func (c *otConn) QueryContext(
132141

133142
method := MethodConnQuery
134143
onDefer := recordMetric(ctx, c.cfg.Instruments, c.cfg, method, query, args)
144+
135145
defer func() {
136146
onDefer(err)
137147
}()
138148

139149
var span trace.Span
150+
140151
queryCtx := ctx
141152
if !c.cfg.SpanOptions.OmitConnQuery && filterSpan(ctx, c.cfg.SpanOptions, method, query, args) {
142153
queryCtx, span = createSpan(ctx, c.cfg, method, true, query, args)
@@ -148,12 +159,14 @@ func (c *otConn) QueryContext(
148159
recordSpanError(span, c.cfg.SpanOptions, err)
149160
return nil, err
150161
}
162+
151163
return newRows(ctx, rows, c.cfg), nil
152164
}
153165

154166
func (c *otConn) PrepareContext(ctx context.Context, query string) (stmt driver.Stmt, err error) {
155167
method := MethodConnPrepare
156168
onDefer := recordMetric(ctx, c.cfg.Instruments, c.cfg, method, query, nil)
169+
157170
defer func() {
158171
onDefer(err)
159172
}()
@@ -190,13 +203,16 @@ func (c *otConn) PrepareContext(ctx context.Context, query string) (stmt driver.
190203
func (c *otConn) BeginTx(ctx context.Context, opts driver.TxOptions) (tx driver.Tx, err error) {
191204
method := MethodConnBeginTx
192205
onDefer := recordMetric(ctx, c.cfg.Instruments, c.cfg, method, "", nil)
206+
193207
defer func() {
194208
onDefer(err)
195209
}()
196210

197211
var beginTxCtx context.Context
212+
198213
if filterSpan(ctx, c.cfg.SpanOptions, method, "", nil) {
199214
var span trace.Span
215+
200216
beginTxCtx, span = createSpan(ctx, c.cfg, method, false, "", nil)
201217
defer span.End()
202218
defer recordSpanErrorDeferred(span, c.cfg.SpanOptions, &err)
@@ -236,6 +252,7 @@ func (c *otConn) BeginTx(ctx context.Context, opts driver.TxOptions) (tx driver.
236252
}
237253
}
238254
}
255+
239256
return newTx(ctx, tx, c.cfg), nil
240257
}
241258

@@ -248,6 +265,7 @@ func (c *otConn) ResetSession(ctx context.Context) (err error) {
248265

249266
method := MethodConnResetSession
250267
onDefer := recordMetric(ctx, c.cfg.Instruments, c.cfg, method, "", nil)
268+
251269
defer func() {
252270
onDefer(err)
253271
}()
@@ -263,6 +281,7 @@ func (c *otConn) ResetSession(ctx context.Context) (err error) {
263281
recordSpanError(span, c.cfg.SpanOptions, err)
264282
return err
265283
}
284+
266285
return nil
267286
}
268287

conn_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,28 +102,34 @@ func newMockConn(shouldError bool) *mockConn {
102102
func (m *mockConn) ResetSession(ctx context.Context) error {
103103
m.resetSessionCtx = ctx
104104
m.resetSessionCount++
105+
105106
if m.shouldError {
106107
return errors.New("resetSession")
107108
}
109+
108110
return nil
109111
}
110112

111113
func (m *mockConn) BeginTx(ctx context.Context, _ driver.TxOptions) (driver.Tx, error) {
112114
m.beginTxCount++
115+
113116
m.beginTxCtx = ctx
114117
if m.shouldError {
115118
return nil, errors.New("beginTx")
116119
}
120+
117121
return newMockTx(false), nil
118122
}
119123

120124
func (m *mockConn) PrepareContext(ctx context.Context, query string) (driver.Stmt, error) {
121125
m.prepareContextCount++
122126
m.prepareContextCtx = ctx
123127
m.prepareContextQuery = query
128+
124129
if m.shouldError {
125130
return nil, errors.New("prepareContext")
126131
}
132+
127133
return newMockStmt(false), nil
128134
}
129135

@@ -133,9 +139,11 @@ func (m *mockConn) QueryContext(
133139
m.queryContextCount++
134140
m.queryContextCtx = ctx
135141
m.queryContextQuery = query
142+
136143
if m.shouldError {
137144
return nil, errors.New("queryContext")
138145
}
146+
139147
return newMockRows(false), nil
140148
}
141149

@@ -145,18 +153,22 @@ func (m *mockConn) ExecContext(
145153
m.execContextCount++
146154
m.execContextCtx = ctx
147155
m.execContextQuery = query
156+
148157
if m.shouldError {
149158
return nil, errors.New("execContext")
150159
}
160+
151161
return nil, nil //nolint:nilnil
152162
}
153163

154164
func (m *mockConn) Ping(ctx context.Context) error {
155165
m.pingCount++
166+
156167
m.pingCtx = ctx
157168
if m.shouldError {
158169
return errors.New("execContext")
159170
}
171+
160172
return nil
161173
}
162174

@@ -245,6 +257,7 @@ func TestOtConn_Ping(t *testing.T) {
245257
}
246258

247259
spanList := sr.Ended()
260+
248261
if tc.pingOption {
249262
omit := !filterSpan(ctx, cfg.SpanOptions, MethodConnPing, "", []driver.NamedValue{})
250263
expectedSpanCount := getExpectedSpanCount(tc.noParentSpan, omit)
@@ -311,6 +324,7 @@ func TestOtConn_ExecContext(t *testing.T) {
311324
attrs: expectedAttrs,
312325
},
313326
}
327+
314328
for _, spanFilterFn := range []SpanFilter{nil, omit, keep} {
315329
testname := testSpanFilterOmit
316330
if spanFilterFn == nil {
@@ -327,6 +341,7 @@ func TestOtConn_ExecContext(t *testing.T) {
327341

328342
// New conn
329343
t.Setenv("OTEL_SEMCONV_STABILITY_OPT_IN", "database")
344+
330345
cfg := newConfig()
331346
cfg.Tracer = tracer
332347
cfg.SpanOptions.DisableQuery = tc.disableQuery
@@ -432,6 +447,7 @@ func TestOtConn_QueryContext(t *testing.T) {
432447

433448
// New conn
434449
t.Setenv("OTEL_SEMCONV_STABILITY_OPT_IN", "database")
450+
435451
cfg := newConfig()
436452
cfg.Tracer = tracer
437453
cfg.SpanOptions.DisableQuery = tc.disableQuery
@@ -450,6 +466,7 @@ func TestOtConn_QueryContext(t *testing.T) {
450466
}
451467

452468
spanList := sr.Ended()
469+
453470
omit := omitConnQuery
454471
if !omit {
455472
omit = !filterSpan(ctx, cfg.SpanOptions, MethodConnQuery, query, args)
@@ -478,6 +495,7 @@ func TestOtConn_QueryContext(t *testing.T) {
478495
if !tc.error {
479496
otelRows, ok := rows.(*otRows)
480497
require.True(t, ok)
498+
481499
if dummySpan != nil && !omit {
482500
assert.Equal(
483501
t,
@@ -572,6 +590,7 @@ func TestOtConn_PrepareContext(t *testing.T) {
572590

573591
// New conn
574592
t.Setenv("OTEL_SEMCONV_STABILITY_OPT_IN", "database")
593+
575594
cfg := newConfig()
576595
cfg.Tracer = tracer
577596
cfg.SpanOptions.DisableQuery = tc.disableQuery
@@ -586,6 +605,7 @@ func TestOtConn_PrepareContext(t *testing.T) {
586605
} else {
587606
mc = newMockConn(tc.error)
588607
}
608+
589609
otelConn := newConn(mc, cfg)
590610

591611
stmt, err := otelConn.PrepareContext(ctx, query)
@@ -596,6 +616,7 @@ func TestOtConn_PrepareContext(t *testing.T) {
596616
}
597617

598618
spanList := sr.Ended()
619+
599620
omit := omitConnPrepare
600621
if !omit {
601622
omit = !filterSpan(
@@ -606,6 +627,7 @@ func TestOtConn_PrepareContext(t *testing.T) {
606627
[]driver.NamedValue{},
607628
)
608629
}
630+
609631
expectedSpanCount := getExpectedSpanCount(tc.noParentSpan, omit)
610632
// One dummy span and one span created in PrepareContext
611633
require.Len(t, spanList, expectedSpanCount)
@@ -688,6 +710,7 @@ func TestOtConn_BeginTx(t *testing.T) {
688710

689711
// New conn
690712
t.Setenv("OTEL_SEMCONV_STABILITY_OPT_IN", "database")
713+
691714
cfg := newConfig()
692715
cfg.Tracer = tracer
693716
cfg.SpanOptions.SpanFilter = spanFilterFn
@@ -699,6 +722,7 @@ func TestOtConn_BeginTx(t *testing.T) {
699722
} else {
700723
mc = newMockConn(tc.error)
701724
}
725+
702726
otelConn := newConn(mc, cfg)
703727

704728
tx, err := otelConn.BeginTx(ctx, driver.TxOptions{})
@@ -773,6 +797,7 @@ func TestOtConn_ResetSession(t *testing.T) {
773797
if omitResetSession {
774798
testname = "OmitConnResetSession"
775799
}
800+
776801
t.Run(testname, func(t *testing.T) {
777802
for _, spanFilterFn := range []SpanFilter{nil, omit, keep} {
778803
testname := testSpanFilterOmit
@@ -781,6 +806,7 @@ func TestOtConn_ResetSession(t *testing.T) {
781806
} else if spanFilterFn(nil, "", "", []driver.NamedValue{}) {
782807
testname = testSpanFilterKeep
783808
}
809+
784810
t.Run(testname, func(t *testing.T) {
785811
for _, tc := range testCases {
786812
t.Run(tc.name, func(t *testing.T) {
@@ -789,6 +815,7 @@ func TestOtConn_ResetSession(t *testing.T) {
789815

790816
// New conn
791817
t.Setenv("OTEL_SEMCONV_STABILITY_OPT_IN", "database")
818+
792819
cfg := newConfig()
793820
cfg.Tracer = tracer
794821
cfg.SpanOptions.OmitConnResetSession = omitResetSession
@@ -806,6 +833,7 @@ func TestOtConn_ResetSession(t *testing.T) {
806833
}
807834

808835
spanList := sr.Ended()
836+
809837
omit := omitResetSession
810838
if !omit {
811839
omit = !filterSpan(
@@ -816,6 +844,7 @@ func TestOtConn_ResetSession(t *testing.T) {
816844
[]driver.NamedValue{},
817845
)
818846
}
847+
819848
expectedSpanCount := getExpectedSpanCount(tc.noParentSpan, omit)
820849
// One dummy span and one span created in ResetSession
821850
require.Len(t, spanList, expectedSpanCount)

0 commit comments

Comments
 (0)