File tree Expand file tree Collapse file tree 4 files changed +58
-7
lines changed Expand file tree Collapse file tree 4 files changed +58
-7
lines changed Original file line number Diff line number Diff line change 17
17
# Dependency directories (remove the comment below to include it)
18
18
# vendor/
19
19
src /
20
+
21
+ .vscode
Original file line number Diff line number Diff line change @@ -17,7 +17,6 @@ linters:
17
17
- errcheck
18
18
- errname
19
19
- errorlint
20
- - exhaustive # checks exhaustiveness of enum switch statements
21
20
- exportloopref # checks for pointers to enclosing loop variables
22
21
- gci
23
22
- gochecknoinits # checks that no init functions are present in Go code
@@ -59,12 +58,6 @@ linters-settings:
59
58
- standard # Standard section: captures all standard packages.
60
59
- default # Default section: contains all imports that could not be matched to another section type.
61
60
- prefix(github.com/jjti)
62
- exhaustive :
63
- # Program elements to check for exhaustiveness.
64
- # Default: [ switch ]
65
- check :
66
- - switch
67
- - map
68
61
gocritic :
69
62
settings :
70
63
captLocal :
Original file line number Diff line number Diff line change @@ -309,6 +309,11 @@ outer:
309
309
}
310
310
seen [b ] = true
311
311
312
+ // Skip successors that are not nested within this current block.
313
+ if _ , ok := nestedBlockTypes [b .Kind ]; ! ok {
314
+ continue
315
+ }
316
+
312
317
// Prune the search if the block uses v.
313
318
if blockUses (pass , b ) {
314
319
continue
@@ -330,6 +335,21 @@ outer:
330
335
return search (defBlock .Succs )
331
336
}
332
337
338
+ var nestedBlockTypes = map [cfg.BlockKind ]struct {}{
339
+ cfg .KindBody : {},
340
+ cfg .KindForBody : {},
341
+ cfg .KindForLoop : {},
342
+ cfg .KindIfElse : {},
343
+ cfg .KindIfThen : {},
344
+ cfg .KindLabel : {},
345
+ cfg .KindRangeBody : {},
346
+ cfg .KindRangeLoop : {},
347
+ cfg .KindSelectCaseBody : {},
348
+ cfg .KindSelectAfterCase : {},
349
+ cfg .KindSwitchCaseBody : {},
350
+ cfg .KindSwitchNextCase : {},
351
+ }
352
+
333
353
// usesCall reports whether stmts contain a use of the selName call on variable v.
334
354
func usesCall (
335
355
pass * analysis.Pass ,
Original file line number Diff line number Diff line change @@ -213,3 +213,39 @@ func testStartTrace() *trace.Span { // no error expected because this is in extr
213
213
_ , span := trace .StartSpan (context .Background (), "bar" )
214
214
return span
215
215
}
216
+
217
+ // https://github.com/jjti/go-spancheck/issues/25
218
+ func _ () error {
219
+ if true {
220
+ _ , span := otel .Tracer ("foo" ).Start (context .Background (), "bar" )
221
+ span .End ()
222
+ }
223
+
224
+ return errors .New ("test" )
225
+ }
226
+
227
+ func _ () error {
228
+ if true {
229
+ _ , span := otel .Tracer ("foo" ).Start (context .Background (), "bar" ) // want "span.SetStatus is not called on all paths"
230
+ defer span .End ()
231
+
232
+ if true {
233
+ span .RecordError (errors .New ("test" ))
234
+ return errors .New ("test" ) // want "return can be reached without calling span.SetStatus"
235
+ }
236
+ }
237
+
238
+ return errors .New ("test" )
239
+ }
240
+
241
+ // TODO: the check below now fails after the change to fix issue 25 above.
242
+ // func _() error {
243
+ // var span *trace.Span
244
+
245
+ // if true {
246
+ // _, span = trace.StartSpan(context.Background(), "foo")
247
+ // defer span.End()
248
+ // }
249
+
250
+ // return errors.New("test")
251
+ // }
You can’t perform that action at this time.
0 commit comments