-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Fernandez Ludovic <ldez@users.noreply.github.com>
- Loading branch information
Showing
12 changed files
with
402 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package golinters | ||
|
||
import ( | ||
"github.com/jjti/go-spancheck" | ||
"golang.org/x/tools/go/analysis" | ||
|
||
"github.com/golangci/golangci-lint/pkg/config" | ||
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis" | ||
) | ||
|
||
func NewSpancheck(settings *config.SpancheckSettings) *goanalysis.Linter { | ||
cfg := spancheck.NewDefaultConfig() | ||
|
||
if settings != nil { | ||
if settings.Checks != nil { | ||
cfg.EnabledChecks = settings.Checks | ||
} | ||
|
||
if settings.IgnoreCheckSignatures != nil { | ||
cfg.IgnoreChecksSignaturesSlice = settings.IgnoreCheckSignatures | ||
} | ||
} | ||
|
||
a := spancheck.NewAnalyzerWithConfig(cfg) | ||
|
||
return goanalysis. | ||
NewLinter(a.Name, a.Doc, []*analysis.Analyzer{a}, nil). | ||
WithLoadMode(goanalysis.LoadModeTypesInfo) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
linters-settings: | ||
spancheck: | ||
checks: | ||
- "end" | ||
- "record-error" | ||
- "set-status" | ||
ignore-check-signatures: | ||
- "recordErr" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module spancheck | ||
|
||
go 1.20 | ||
|
||
require ( | ||
go.opentelemetry.io/otel v1.21.0 | ||
go.opentelemetry.io/otel/trace v1.21.0 | ||
) | ||
|
||
require ( | ||
github.com/go-logr/logr v1.4.1 // indirect | ||
github.com/go-logr/stdr v1.2.2 // indirect | ||
go.opentelemetry.io/otel/metric v1.21.0 // indirect | ||
) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
//golangcitest:args -Espancheck | ||
package spancheck | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
|
||
"go.opentelemetry.io/otel" | ||
"go.opentelemetry.io/otel/codes" | ||
) | ||
|
||
type testDefaultError struct{} | ||
|
||
func (e *testDefaultError) Error() string { | ||
return "foo" | ||
} | ||
|
||
// incorrect | ||
|
||
func _() { | ||
otel.Tracer("foo").Start(context.Background(), "bar") // want "span is unassigned, probable memory leak" | ||
ctx, _ := otel.Tracer("foo").Start(context.Background(), "bar") // want "span is unassigned, probable memory leak" | ||
fmt.Print(ctx) | ||
} | ||
|
||
func _() { | ||
ctx, span := otel.Tracer("foo").Start(context.Background(), "bar") // want "span.End is not called on all paths, possible memory leak" | ||
print(ctx.Done(), span.IsRecording()) | ||
} // want "return can be reached without calling span.End" | ||
|
||
func _() { | ||
var ctx, span = otel.Tracer("foo").Start(context.Background(), "bar") // want "span.End is not called on all paths, possible memory leak" | ||
print(ctx.Done(), span.IsRecording()) | ||
} // want "return can be reached without calling span.End" | ||
|
||
func _() { | ||
_, span := otel.Tracer("foo").Start(context.Background(), "bar") // want "span.End is not called on all paths, possible memory leak" | ||
_, span = otel.Tracer("foo").Start(context.Background(), "bar") | ||
fmt.Print(span) | ||
defer span.End() | ||
} // want "return can be reached without calling span.End" | ||
|
||
// correct | ||
|
||
func _() error { | ||
_, span := otel.Tracer("foo").Start(context.Background(), "bar") | ||
defer span.End() | ||
|
||
return nil | ||
} | ||
|
||
func _() error { | ||
_, span := otel.Tracer("foo").Start(context.Background(), "bar") | ||
defer span.End() | ||
|
||
if true { | ||
return nil | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func _() error { | ||
_, span := otel.Tracer("foo").Start(context.Background(), "bar") | ||
defer span.End() | ||
|
||
if false { | ||
err := errors.New("foo") | ||
span.SetStatus(codes.Error, err.Error()) | ||
span.RecordError(err) | ||
return err | ||
} | ||
|
||
if true { | ||
span.SetStatus(codes.Error, "foo") | ||
span.RecordError(errors.New("foo")) | ||
return errors.New("bar") | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func _() { | ||
_, span := otel.Tracer("foo").Start(context.Background(), "bar") | ||
defer span.End() | ||
|
||
_, span = otel.Tracer("foo").Start(context.Background(), "bar") | ||
defer span.End() | ||
} |
Oops, something went wrong.