From 33c50907fcb2c85f6775e8037f0187a07a43befb Mon Sep 17 00:00:00 2001 From: Sung Yoon Whang Date: Wed, 1 Jul 2026 12:58:20 -0700 Subject: [PATCH] fix golangci-lint detected issues This fixes all issues discovered while enabling golangci-lint in this repo. This includes all checks included by the default golangci-lint configuration, including but not limited to: - staticcheck - errcheck - ineffassign - dead code Will follow up with another PR to enable the CI check for this. --- controller/BUILD.bazel | 1 + controller/getchangedtargetgraph.go | 2 +- controller/getchangedtargets.go | 19 ++++--- controller/getchangedtargets_test.go | 2 +- controller/gettargetgraph_test.go | 2 +- core/bazel/bazel_test.go | 2 +- core/bazel/query_test.go | 14 +++--- core/bazel/stream.go | 46 +++++++---------- core/git/git_test.go | 4 +- core/repomanager/repo_manager.go | 2 +- core/storage/memstorage.go | 6 +-- core/targethasher/BUILD.bazel | 4 +- core/targethasher/graph.go | 13 ----- core/targethasher/graph_test.go | 37 +++----------- core/targethasher/mock_sourcehasher_test.go | 56 +++++++++++++++++++++ core/targethasher/sourcehasher.go | 13 ++--- example/client/client.go | 14 ++---- example/cmd/query-bench/main.go | 2 +- example/main.go | 9 ++-- graphrunner/shell.go | 2 +- orchestrator/native_orchestrator_test.go | 10 ++-- 21 files changed, 134 insertions(+), 126 deletions(-) create mode 100644 core/targethasher/mock_sourcehasher_test.go diff --git a/controller/BUILD.bazel b/controller/BUILD.bazel index 581ba3b..acdcd30 100644 --- a/controller/BUILD.bazel +++ b/controller/BUILD.bazel @@ -17,6 +17,7 @@ go_library( "//config", "//core/common", "//core/storage", + "//core/targethasher", "//orchestrator", "//tangopb", "@com_github_uber_go_tally//:tally", diff --git a/controller/getchangedtargetgraph.go b/controller/getchangedtargetgraph.go index c8b65c0..123733e 100644 --- a/controller/getchangedtargetgraph.go +++ b/controller/getchangedtargetgraph.go @@ -21,7 +21,7 @@ import ( // GetChangedTargetGraph is the streaming RPC that will return the subgraph // induced by the changed targets between two revisions. It is currently a // stub: it records success/failure metrics and returns no data. -func (c *controller) GetChangedTargetGraph(request *pb.GetChangedTargetGraphRequest, stream pb.TangoServiceGetChangedTargetGraphYARPCServer) (retErr error) { +func (c *controller) GetChangedTargetGraph(_ *pb.GetChangedTargetGraphRequest, _ pb.TangoServiceGetChangedTargetGraphYARPCServer) (retErr error) { scope := c.scope.SubScope("get_changed_target_graph") defer func() { if retErr != nil { diff --git a/controller/getchangedtargets.go b/controller/getchangedtargets.go index 1014984..d6d4176 100644 --- a/controller/getchangedtargets.go +++ b/controller/getchangedtargets.go @@ -23,6 +23,7 @@ import ( "github.com/uber/tango/core/common" "github.com/uber/tango/core/storage" + "github.com/uber/tango/core/targethasher" pb "github.com/uber/tango/tangopb" "go.uber.org/zap" ) @@ -40,6 +41,8 @@ type job struct { // GetChangedTargets returns the changed targets between two revisions. If the // client disconnects, the stream's context is cancelled and the function // returns with context.Canceled. +// +//nolint:gocyclo // orchestration method with inherently high branching func (c *controller) GetChangedTargets(request *pb.GetChangedTargetsRequest, stream pb.TangoServiceGetChangedTargetsYARPCServer) (retErr error) { scope := c.scope.SubScope("get_changed_targets") scope.Counter("calls").Inc(1) @@ -257,8 +260,8 @@ func (c *controller) GetChangedTargets(request *pb.GetChangedTargetsRequest, str compareStart := time.Now() changedTargetsResponses, err := c.compareTargetGraphs(ctx, logger, firstGraph, secondGraph, maxDist) // Allow GC of raw graph data while the caching goroutine runs. - firstGraph = nil - secondGraph = nil + firstGraph = nil //nolint:ineffassign // intentional: allow GC of large slice + secondGraph = nil //nolint:ineffassign // intentional: allow GC of large slice if err != nil { if ctx.Err() != nil { return common.WithReason(common.FailureReasonCancelled, common.ErrorTypeUser, ctx.Err()) @@ -331,6 +334,8 @@ func (c *controller) GetChangedTargets(request *pb.GetChangedTargetsRequest, str // targets get their distance from BFS over the reverse-dep graph. // Output IDs are re-mapped into a canonical per-call namespace so the // response metadata only carries the names actually referenced. +// +//nolint:gocyclo // comparison pipeline with multiple indexed data structures func (c *controller) compareTargetGraphs(ctx context.Context, logger *zap.Logger, firstGraph, secondGraph []*pb.GetTargetGraphResponse, maxDist int32) ([]*pb.GetChangedTargetsResponse, error) { start := time.Now() scope := c.scope.SubScope("compare_target_graphs") @@ -347,18 +352,18 @@ func (c *controller) compareTargetGraphs(ctx context.Context, logger *zap.Logger return nil, err } // Release raw chunk slices — individual target protos are now held by the ID maps. - firstGraph = nil - secondGraph = nil + firstGraph = nil //nolint:ineffassign // intentional: allow GC of large slice + secondGraph = nil //nolint:ineffassign // intentional: allow GC of large slice firstByName, err := buildNameIndex(ctx, firstTargetsByID, firstMetadata) if err != nil { return nil, err } - firstTargetsByID = nil // all pointers are now in firstByName; drop the duplicate map + firstTargetsByID = nil //nolint:ineffassign // intentional: allow GC of duplicate map secondByName, err := buildNameIndex(ctx, secondTargetsByID, secondMetadata) if err != nil { return nil, err } - secondTargetsByID = nil + secondTargetsByID = nil //nolint:ineffassign // intentional: allow GC of duplicate map indexDuration := time.Since(indexStart) scope.Timer("index_duration").Record(indexDuration) @@ -671,7 +676,7 @@ func detectSourceFileID(meta *pb.Metadata) int32 { } // check the id in the rule type mapping for "source file" for id, name := range meta.GetRuleTypeMapping() { - if name == "source file" { + if name == targethasher.SourceFileType { return id } } diff --git a/controller/getchangedtargets_test.go b/controller/getchangedtargets_test.go index 1e854fc..2c7baf3 100644 --- a/controller/getchangedtargets_test.go +++ b/controller/getchangedtargets_test.go @@ -344,7 +344,7 @@ func TestGetChangedTargets_streamChunks(t *testing.T) { stream.EXPECT().Context().Return(context.Background()) var sentResponses []*pb.GetChangedTargetsResponse - stream.EXPECT().Send(gomock.Any()).DoAndReturn(func(resp *pb.GetChangedTargetsResponse, opts ...interface{}) error { + stream.EXPECT().Send(gomock.Any()).DoAndReturn(func(resp *pb.GetChangedTargetsResponse, _ ...interface{}) error { sentResponses = append(sentResponses, resp) return nil }).Times(2) diff --git a/controller/gettargetgraph_test.go b/controller/gettargetgraph_test.go index e62856f..353ead3 100644 --- a/controller/gettargetgraph_test.go +++ b/controller/gettargetgraph_test.go @@ -391,5 +391,5 @@ func newMockReadCloser(data []byte) io.ReadCloser { type errReadCloser struct{ err error } -func (e *errReadCloser) Read(p []byte) (int, error) { return 0, e.err } +func (e *errReadCloser) Read(_ []byte) (int, error) { return 0, e.err } func (e *errReadCloser) Close() error { return nil } diff --git a/core/bazel/bazel_test.go b/core/bazel/bazel_test.go index c76342a..018c305 100644 --- a/core/bazel/bazel_test.go +++ b/core/bazel/bazel_test.go @@ -36,7 +36,7 @@ func TestNewBazelClient(t *testing.T) { WorkspacePath: "/tmp/test", EnvVarsMap: map[string]string{"FOO": "bar"}, Logger: zap.NewNop().Sugar(), - ExecCommandContext: func(ctx context.Context, name string, arg ...string) commander { + ExecCommandContext: func(_ context.Context, _ string, _ ...string) commander { return nil }, }, diff --git a/core/bazel/query_test.go b/core/bazel/query_test.go index c506214..72a4e70 100644 --- a/core/bazel/query_test.go +++ b/core/bazel/query_test.go @@ -61,10 +61,11 @@ func TestExecuteQuery_Success(t *testing.T) { WorkspacePath: "/tmp/test", EnvVarsMap: map[string]string{}, Logger: zap.NewNop().Sugar(), - ExecCommandContext: func(ctx context.Context, name string, arg ...string) commander { + ExecCommandContext: func(_ context.Context, _ string, _ ...string) commander { return mockCmd }, }) + require.NoError(t, err) resp, err := client.ExecuteQuery(context.Background(), &QueryRequest{Query: "//..."}) require.NoError(t, err) @@ -105,7 +106,7 @@ func TestExecuteQuery_WithStartupOptions(t *testing.T) { WorkspacePath: "/tmp/test", EnvVarsMap: map[string]string{}, Logger: zap.NewNop().Sugar(), - ExecCommandContext: func(ctx context.Context, name string, arg ...string) commander { + ExecCommandContext: func(_ context.Context, _ string, arg ...string) commander { capturedArgs = arg return mockCmd }, @@ -156,7 +157,7 @@ func TestExecuteQueryInternal_ContextTimeout(t *testing.T) { EnvVarsMap: map[string]string{}, QueryTimeout: 10 * time.Millisecond, // Short timeout for test - ExecCommandContext: func(ctx context.Context, name string, arg ...string) commander { + ExecCommandContext: func(ctx context.Context, _ string, _ ...string) commander { // Simulate process behavior: when context is cancelled, close pipes go func() { <-ctx.Done() @@ -169,7 +170,7 @@ func TestExecuteQueryInternal_ContextTimeout(t *testing.T) { }) require.NoError(t, err) result, err := client.executeQueryInternal(context.Background(), "//...", nil) - require.Nil(t, result) + require.Empty(t, result.GetTarget()) require.Error(t, err) // Should get timeout or deadline exceeded error assert.Contains(t, err.Error(), "deadline exceeded") @@ -234,7 +235,7 @@ func TestExecuteQueryInternal_Failures(t *testing.T) { WorkspacePath: "/tmp/test", EnvVarsMap: map[string]string{}, Logger: zap.NewNop().Sugar(), - ExecCommandContext: func(ctx context.Context, name string, arg ...string) commander { + ExecCommandContext: func(_ context.Context, _ string, _ ...string) commander { return mockCmd }, }) @@ -263,10 +264,11 @@ func TestExecuteQuery_ErrorCase(t *testing.T) { WorkspacePath: "/tmp/test", EnvVarsMap: map[string]string{}, Logger: zap.NewNop().Sugar(), - ExecCommandContext: func(ctx context.Context, name string, arg ...string) commander { + ExecCommandContext: func(_ context.Context, _ string, _ ...string) commander { return mockCmd }, }) + require.NoError(t, err) resp, err := client.ExecuteQuery(context.Background(), &QueryRequest{Query: "//..."}) require.Error(t, err) diff --git a/core/bazel/stream.go b/core/bazel/stream.go index 2e78fd7..6c5e030 100644 --- a/core/bazel/stream.go +++ b/core/bazel/stream.go @@ -24,38 +24,28 @@ import ( ) func streamOutput(ctx context.Context, src io.Reader, dst io.Writer) error { - done := make(chan error, 1) - go func() { - _, err := io.Copy(dst, src) - done <- err - }() - - select { - case <-ctx.Done(): - return ctx.Err() - case err := <-done: - return err + buf := make([]byte, 32*1024) + for { + if err := ctx.Err(); err != nil { + return err + } + n, readErr := src.Read(buf) + if n > 0 { + if _, writeErr := dst.Write(buf[:n]); writeErr != nil { + return writeErr + } + } + if readErr != nil { + if readErr == io.EOF { + return nil + } + return readErr + } } } func streamAndParseTargets(ctx context.Context, src io.Reader, dst io.Writer) (*buildpb.QueryResult, error) { - type result struct { - queryResult *buildpb.QueryResult - err error - } - done := make(chan result, 1) - - go func() { - queryResult, err := getQueryResult(ctx, src, dst) - done <- result{queryResult: queryResult, err: err} - }() - - select { - case <-ctx.Done(): - return nil, ctx.Err() - case res := <-done: - return res.queryResult, res.err - } + return getQueryResult(ctx, src, dst) } // cancelCheckInterval is how often we poll ctx.Err() inside per-target hot loops. diff --git a/core/git/git_test.go b/core/git/git_test.go index 72ebba8..01383f0 100644 --- a/core/git/git_test.go +++ b/core/git/git_test.go @@ -226,8 +226,8 @@ func TestDefaultGit_FileHashes(t *testing.T) { `100644 blob d236 file1 100644 blob 9bcc file2`), wantHashes: map[string][]byte{ - "file1": []byte{0xd2, 0x36}, - "file2": []byte{0x9b, 0xcc}, + "file1": {0xd2, 0x36}, + "file2": {0x9b, 0xcc}, }, }, { diff --git a/core/repomanager/repo_manager.go b/core/repomanager/repo_manager.go index 2bd5f60..2b52f90 100644 --- a/core/repomanager/repo_manager.go +++ b/core/repomanager/repo_manager.go @@ -59,7 +59,7 @@ type repoManager struct { // The origin directory holds the initial clone; workers are cheap local copies. type workerPool struct { originDir string - originMu sync.Mutex // one lock per repo for orginal clone + originMu sync.Mutex // one lock per repo for original clone cloned bool avail chan *workerSlot // available slots; pool capacity diff --git a/core/storage/memstorage.go b/core/storage/memstorage.go index 0868dae..f34bc2d 100644 --- a/core/storage/memstorage.go +++ b/core/storage/memstorage.go @@ -36,7 +36,7 @@ func NewMemoryStorage() Storage { } // Get downloads a blob from the storage. Return NotFoundError when the blob is not found. -func (m *memoryStorage) Get(ctx context.Context, req DownloadRequest) (DownloadResponse, error) { +func (m *memoryStorage) Get(_ context.Context, req DownloadRequest) (DownloadResponse, error) { m.mu.RLock() defer m.mu.RUnlock() b, ok := m.data[req.Key] @@ -60,14 +60,14 @@ func (m *memoryStorage) Put(ctx context.Context, req UploadRequest) error { return nil } -func (m *memoryStorage) Exists(ctx context.Context, key string) (bool, error) { +func (m *memoryStorage) Exists(_ context.Context, key string) (bool, error) { m.mu.RLock() defer m.mu.RUnlock() _, ok := m.data[key] return ok, nil } -func (m *memoryStorage) List(ctx context.Context, prefix string) ([]string, error) { +func (m *memoryStorage) List(_ context.Context, prefix string) ([]string, error) { m.mu.RLock() defer m.mu.RUnlock() var keys []string diff --git a/core/targethasher/BUILD.bazel b/core/targethasher/BUILD.bazel index ef290df..5746c71 100644 --- a/core/targethasher/BUILD.bazel +++ b/core/targethasher/BUILD.bazel @@ -30,11 +30,9 @@ go_test( "//core/bazel", "@com_github_bazelbuild_buildtools//build_proto", "@com_github_deckarep_golang_set_v2//:golang-set", - "@com_github_golang_mock//gomock", - "@com_github_google_go_cmp//cmp", - "@com_github_google_go_cmp//cmp/cmpopts", "@com_github_stretchr_testify//assert", "@com_github_stretchr_testify//require", + "@org_uber_go_mock//gomock", ], ) diff --git a/core/targethasher/graph.go b/core/targethasher/graph.go index 29ad9a5..f7af2ec 100644 --- a/core/targethasher/graph.go +++ b/core/targethasher/graph.go @@ -734,19 +734,6 @@ func isExternalTarget(targetName string) bool { return strings.HasPrefix(targetName, externalWorkspaceFilePrefix) } -func isExternalWorkspaceType(t *buildpb.Target) bool { - switch *t.Type { - case buildpb.Target_SOURCE_FILE: - return strings.HasPrefix(t.SourceFile.GetName(), externalWorkspaceRulePrefix) - case buildpb.Target_RULE: - return strings.HasPrefix(t.Rule.GetName(), externalWorkspaceRulePrefix) - case buildpb.Target_GENERATED_FILE: - return strings.HasPrefix(t.GeneratedFile.GetName(), externalWorkspaceRulePrefix) - default: - return false - } -} - func isExcluded(targetName string, excludedRegex []*regexp.Regexp) bool { for _, re := range excludedRegex { if re.MatchString(targetName) { diff --git a/core/targethasher/graph_test.go b/core/targethasher/graph_test.go index 2cf745a..8b1aeca 100644 --- a/core/targethasher/graph_test.go +++ b/core/targethasher/graph_test.go @@ -22,11 +22,9 @@ import ( buildpb "github.com/bazelbuild/buildtools/build_proto" set "github.com/deckarep/golang-set/v2" - "github.com/golang/mock/gomock" - "github.com/google/go-cmp/cmp" - "github.com/google/go-cmp/cmp/cmpopts" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/mock/gomock" "github.com/uber/tango/core/bazel" ) @@ -77,7 +75,7 @@ func TestContextCancellation(t *testing.T) { // verify fromProto honors context cancellation qr := &buildpb.QueryResult{ - Target: []*buildpb.Target{&buildpb.Target{}}, + Target: []*buildpb.Target{{}}, } result, err := fromProto(ctx, qr, nil, "", set.NewSet[string](), set.NewSet[string](), nil, false) assert.Equal(t, EmptyResult(), result) @@ -219,15 +217,15 @@ func Test_RemoveAttrs(t *testing.T) { Rule: &buildpb.Rule{ Name: StringPtr("//pkg:go_default_library"), Attribute: []*buildpb.Attribute{ - &buildpb.Attribute{ + { Name: StringPtr("url"), StringValue: StringPtr("some_url"), }, - &buildpb.Attribute{ + { Name: StringPtr("urls"), StringListValue: []string{"url1", "url2"}, }, - &buildpb.Attribute{ + { Name: StringPtr("to_keep"), StringValue: StringPtr("target1"), }, @@ -245,15 +243,15 @@ func Test_RemoveAttrs(t *testing.T) { Rule: &buildpb.Rule{ Name: StringPtr("//external:some_rule"), Attribute: []*buildpb.Attribute{ - &buildpb.Attribute{ + { Name: StringPtr("url"), StringValue: StringPtr("some_url"), }, - &buildpb.Attribute{ + { Name: StringPtr("urls"), StringListValue: []string{"url1", "url2"}, }, - &buildpb.Attribute{ + { Name: StringPtr("to_keep"), StringValue: StringPtr("external"), }, @@ -276,25 +274,6 @@ func Test_RemoveAttrs(t *testing.T) { assert.Equal(t, []byte{0x7c, 0xde, 0x91, 0xc2, 0x94, 0x1a, 0x22, 0xf3, 0xb2, 0x18, 0x7c, 0x21, 0xbf, 0x32, 0x17, 0xc0, 0xa3, 0xf0, 0xc, 0x77}, external.HashWithoutDeps) } -func validateResultIsStable(t *testing.T, baseResult, result Result) { - t.Helper() - require.ElementsMatch(t, baseResult.TargetNames, result.TargetNames) - for _, targetName := range baseResult.TargetNames { - base, ok := baseResult.Targets[targetName] - require.True(t, ok) - res, ok := result.Targets[targetName] - require.True(t, ok) - assert.Equal(t, base.Hash, res.Hash) - } -} - -func assertEqualTargetHash(t *testing.T, expected, actual Target) { - opt := cmpopts.IgnoreUnexported(Target{}) - // too many nested attributes to compare - ignore := cmpopts.IgnoreFields(Target{}, "Attributes", "SourceFile", "Rule") - assert.True(t, cmp.Equal(expected, actual, opt, ignore), cmp.Diff(expected, actual, opt)) -} - func Test_fromProto(t *testing.T) { ctrl := gomock.NewController(t) diff --git a/core/targethasher/mock_sourcehasher_test.go b/core/targethasher/mock_sourcehasher_test.go new file mode 100644 index 0000000..0214964 --- /dev/null +++ b/core/targethasher/mock_sourcehasher_test.go @@ -0,0 +1,56 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: github.com/uber/tango/core/targethasher (interfaces: SourceHasher) +// +// Generated by this command: +// +// mockgen -destination=core/targethasher/mock_sourcehasher_test.go -package=targethasher github.com/uber/tango/core/targethasher SourceHasher +// + +// Package targethasher is a generated GoMock package. +package targethasher + +import ( + reflect "reflect" + + build_proto "github.com/bazelbuild/buildtools/build_proto" + gomock "go.uber.org/mock/gomock" +) + +// MockSourceHasher is a mock of SourceHasher interface. +type MockSourceHasher struct { + ctrl *gomock.Controller + recorder *MockSourceHasherMockRecorder + isgomock struct{} +} + +// MockSourceHasherMockRecorder is the mock recorder for MockSourceHasher. +type MockSourceHasherMockRecorder struct { + mock *MockSourceHasher +} + +// NewMockSourceHasher creates a new mock instance. +func NewMockSourceHasher(ctrl *gomock.Controller) *MockSourceHasher { + mock := &MockSourceHasher{ctrl: ctrl} + mock.recorder = &MockSourceHasherMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockSourceHasher) EXPECT() *MockSourceHasherMockRecorder { + return m.recorder +} + +// HashSourceFile mocks base method. +func (m *MockSourceHasher) HashSourceFile(s *build_proto.SourceFile) ([]byte, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "HashSourceFile", s) + ret0, _ := ret[0].([]byte) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// HashSourceFile indicates an expected call of HashSourceFile. +func (mr *MockSourceHasherMockRecorder) HashSourceFile(s any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HashSourceFile", reflect.TypeOf((*MockSourceHasher)(nil).HashSourceFile), s) +} diff --git a/core/targethasher/sourcehasher.go b/core/targethasher/sourcehasher.go index 5c1c7f2..7511fcf 100644 --- a/core/targethasher/sourcehasher.go +++ b/core/targethasher/sourcehasher.go @@ -72,7 +72,7 @@ func NewSourceHasher(p Params) SourceHasher { } // HashSourceFile does a no-op hash for the noOpHasher. -func (hh *noOpHasher) HashSourceFile(sourceFile *buildpb.SourceFile) ([]byte, error) { +func (hh *noOpHasher) HashSourceFile(_ *buildpb.SourceFile) ([]byte, error) { return nil, nil } @@ -123,7 +123,7 @@ func hashFile(path string) (hash.Hash, error) { hash := newHash() // Using same SHA1 hashing algorithm as git to ensure file hashes // are always the same: https://alblue.bandlem.com/2011/08/git-tip-of-week-objects.html - hash.Write([]byte(fmt.Sprintf("blob %d\000", fi.Size()))) + fmt.Fprintf(hash, "blob %d\000", fi.Size()) if _, err := io.Copy(hash, f); err != nil { return nil, err } @@ -166,13 +166,9 @@ func externalTargetForRule(t string) string { return externalWorkspaceRulePrefix + strings.TrimLeft(strings.Split(t, "//")[0], "@") } -func pathForTarget(root, target string) string { - // //path/to:target.go -> $root/path/to/target.go - parts := strings.SplitN(strings.TrimPrefix(target, "//"), ":", 2) - return filepath.Join(root, parts[0], parts[1]) -} - // HashRuleCommon hashes the common elements of a buildpb.Rule. +// +//nolint:errcheck // hash.Hash.Write never returns an error func HashRuleCommon(r *buildpb.Rule, h hash.Hash) { // Name *string io.WriteString(h, r.GetName()) @@ -216,6 +212,7 @@ func HashRuleCommon(r *buildpb.Rule, h hash.Hash) { io.WriteString(h, r.GetSkylarkEnvironmentHashCode()) } +//nolint:errcheck // hash.Hash.Write never returns an error func hashAttributes(h hash.Hash, a *buildpb.Attribute) { // generator_location is present if the rule is generated from a macro, but // should not be hashed as the generating macro's location in a build file diff --git a/example/client/client.go b/example/client/client.go index 0d2fba5..b5f9a67 100644 --- a/example/client/client.go +++ b/example/client/client.go @@ -50,12 +50,8 @@ func main() { grpcTransport := yarpcgrpc.NewTransport() out := grpcTransport.NewSingleOutbound(*addr) - zl, err := zap.NewDevelopment() - if err != nil { - fmt.Fprintf(os.Stderr, "init logger: %v\n", err) - os.Exit(1) - } - defer zl.Sync() + zl, _ := zap.NewDevelopment() + defer zl.Sync() //nolint:errcheck // best-effort flush logger := zl.Sugar() dispatcher := yarpc.NewDispatcher(yarpc.Config{ Name: "tango-client", @@ -67,7 +63,7 @@ func main() { logger.Errorf("start dispatcher: %w", err) os.Exit(1) } - defer dispatcher.Stop() + defer dispatcher.Stop() //nolint:errcheck // best-effort cleanup client := pb.NewTangoYARPCClient(dispatcher.ClientConfig("tango")) @@ -159,7 +155,7 @@ func callGetTargetGraph(ctx context.Context, client pb.TangoYARPCClient, logger if err != nil { return fmt.Errorf("GetTargetGraph: %w", err) } - defer stream.CloseSend() + defer stream.CloseSend() //nolint:errcheck // best-effort cleanup for { msg, err := stream.Recv() @@ -204,7 +200,7 @@ func callGetChangedTargets(ctx context.Context, client pb.TangoYARPCClient, logg if err != nil { return fmt.Errorf("GetChangedTargets: %w", err) } - defer stream.CloseSend() + defer stream.CloseSend() //nolint:errcheck // best-effort cleanup for { msg, err := stream.Recv() diff --git a/example/cmd/query-bench/main.go b/example/cmd/query-bench/main.go index 3071b01..762a21f 100644 --- a/example/cmd/query-bench/main.go +++ b/example/cmd/query-bench/main.go @@ -66,7 +66,7 @@ func run() error { if err != nil { return fmt.Errorf("creating logger: %w", err) } - defer logger.Sync() + defer logger.Sync() //nolint:errcheck // best-effort flush parentCtx := context.Background() diff --git a/example/main.go b/example/main.go index 991cc31..c49c509 100644 --- a/example/main.go +++ b/example/main.go @@ -45,11 +45,8 @@ func main() { } func run() error { - zl, err := zap.NewDevelopment() - if err != nil { - return fmt.Errorf("init logger: %w", err) - } - defer zl.Sync() + zl, _ := zap.NewDevelopment() + defer zl.Sync() //nolint:errcheck // best-effort flush logger := zl.Sugar() // appCtx is the application-lifetime context. It is cancelled on @@ -125,7 +122,7 @@ func run() error { if err := dispatcher.Start(); err != nil { return fmt.Errorf("failed to start dispatcher: %w", err) } - defer dispatcher.Stop() + defer dispatcher.Stop() //nolint:errcheck // best-effort cleanup logger.Infof("Tango server is running:") logger.Infof("- gRPC inbound: %s", port) diff --git a/graphrunner/shell.go b/graphrunner/shell.go index 411733b..5c9a8c7 100644 --- a/graphrunner/shell.go +++ b/graphrunner/shell.go @@ -42,6 +42,6 @@ func NewShellGraphRunner(p ShellGraphRunnerParams) GraphRunner { } } -func (s *shellGraphRunner) Compute(ctx context.Context, ws workspace.Workspace) (targethasher.Result, error) { +func (s *shellGraphRunner) Compute(_ context.Context, _ workspace.Workspace) (targethasher.Result, error) { return targethasher.EmptyResult(), errors.New("shellGraphRunner.Compute: not yet implemented") } diff --git a/orchestrator/native_orchestrator_test.go b/orchestrator/native_orchestrator_test.go index 9739ad4..3fbeefd 100644 --- a/orchestrator/native_orchestrator_test.go +++ b/orchestrator/native_orchestrator_test.go @@ -67,7 +67,7 @@ func TestNative_GetTargetGraph_Success(t *testing.T) { Storage: st, RepoManager: rm, Logger: zaptest.NewLogger(t).Sugar(), - GitFactory: func(dir string) git.Interface { return g }, + GitFactory: func(_ string) git.Interface { return g }, ConfigFilePath: "testdata/config.yaml", }) reader, err := o.GetTargetGraph(context.Background(), GetTargetGraphParam{ @@ -114,7 +114,7 @@ func TestNative_GetTargetGraph_TreehashNotFound_NoError(t *testing.T) { rm.EXPECT().Lease(gomock.Any(), gomock.Any()).Return(ws, nil) graphRunner := graphmock.NewMockGraphRunner(ctrl) graphRunner.EXPECT().Compute(gomock.Any(), gomock.Any()).Return(targethasher.Result{Targets: map[string]*targethasher.Target{ - "//:a": &targethasher.Target{ + "//:a": { Name: "//:a", RuleType: "go_library", }, @@ -123,7 +123,7 @@ func TestNative_GetTargetGraph_TreehashNotFound_NoError(t *testing.T) { Storage: st, RepoManager: rm, Logger: zaptest.NewLogger(t).Sugar(), - GitFactory: func(dir string) git.Interface { return g }, + GitFactory: func(_ string) git.Interface { return g }, GraphRunner: graphRunner, ConfigFilePath: "testdata/config.yaml", }) @@ -155,7 +155,7 @@ func TestNative_GetTargetGraph_RevParseError_Propagates(t *testing.T) { Storage: st, RepoManager: rm, Logger: zaptest.NewLogger(t).Sugar(), - GitFactory: func(dir string) git.Interface { return g }, + GitFactory: func(_ string) git.Interface { return g }, ConfigFilePath: "testdata/config.yaml", }) resp, err := o.GetTargetGraph(context.Background(), GetTargetGraphParam{ @@ -194,7 +194,7 @@ func TestNative_GetTargetGraph_AppliesGitHubPR(t *testing.T) { Storage: st, RepoManager: rm, Logger: zaptest.NewLogger(t).Sugar(), - GitFactory: func(dir string) git.Interface { return g }, + GitFactory: func(_ string) git.Interface { return g }, ConfigFilePath: "testdata/config.yaml", }) reader, err := o.GetTargetGraph(context.Background(), GetTargetGraphParam{