From 0bc13590eca33f37dc9aaaaf7f0fd37118b0cc7b Mon Sep 17 00:00:00 2001 From: Mihail Stoykov Date: Thu, 6 Mar 2025 12:08:22 +0200 Subject: [PATCH] Update golangci-lint to 1.64.6 and update code to conform --- .golangci.yml | 7 +++--- internal/js/bundle_test.go | 3 +-- internal/js/console_test.go | 2 +- .../k6/browser/browser/registry_test.go | 2 +- .../modules/k6/browser/common/browser_test.go | 2 +- .../k6/browser/common/element_handle.go | 2 +- .../k6/browser/storage/storage_test.go | 4 +-- .../modules/k6/browser/tests/browser_test.go | 21 +++------------- .../js/modules/k6/experimental/fs/file.go | 2 +- .../k6/experimental/websockets/blob.go | 2 +- .../grpc_wrappers_testing/service.go | 25 ++++++++++++------- metrics/builtin.go | 1 - 12 files changed, 31 insertions(+), 42 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 5c9ec15c4ce..19a34a9972d 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,4 +1,4 @@ -# v1.63.4 +# v1.64.6 # Please don't remove the first line. It uses in CI to determine the golangci version run: timeout: 5m @@ -65,6 +65,8 @@ linters-settings: # Forbid everything in syscall except the uppercase constants - '^syscall\.[^A-Z_]+$(# Using anything except constants from the syscall package is forbidden )?' - '^logrus\.Logger$' + usetesting: + os-setenv: true linters: disable-all: true @@ -84,7 +86,6 @@ linters: - errname - errorlint - exhaustive - - exportloopref - fatcontext - forbidigo - forcetypeassert @@ -125,13 +126,13 @@ linters: - sqlclosecheck - staticcheck - stylecheck - - tenv - tparallel - typecheck - unconvert - unparam - unused - usestdlibvars + - usetesting - wastedassign - whitespace fast: false diff --git a/internal/js/bundle_test.go b/internal/js/bundle_test.go index 31e721e5fab..a25c302e48a 100644 --- a/internal/js/bundle_test.go +++ b/internal/js/bundle_test.go @@ -687,8 +687,7 @@ func TestOpen(t *testing.T) { return fs, "", func() {} }, "OsFS": func() (fsext.Fs, string, func()) { - prefix, err := os.MkdirTemp("", "k6_open_test") //nolint:forbidigo - require.NoError(t, err) + prefix := t.TempDir() fs := fsext.NewOsFs() filePath := filepath.Join(prefix, "/path/to/file.txt") require.NoError(t, fs.MkdirAll(filepath.Join(prefix, "/path/to"), 0o755)) diff --git a/internal/js/console_test.go b/internal/js/console_test.go index 93726b2e23c..9ef1e855057 100644 --- a/internal/js/console_test.go +++ b/internal/js/console_test.go @@ -375,7 +375,7 @@ func TestFileConsole(t *testing.T) { msg, deleteFile := msg, deleteFile t.Run(msg, func(t *testing.T) { t.Parallel() - f, err := os.CreateTemp("", "") //nolint:forbidigo // fix with https://github.com/grafana/k6/issues/2565 + f, err := os.CreateTemp(t.TempDir(), "") //nolint:forbidigo // fix with https://github.com/grafana/k6/issues/2565 require.NoError(t, err) logFilename := f.Name() defer os.Remove(logFilename) //nolint:errcheck,forbidigo // fix with https://github.com/grafana/k6/issues/2565 diff --git a/internal/js/modules/k6/browser/browser/registry_test.go b/internal/js/modules/k6/browser/browser/registry_test.go index 4d9b809f6c9..8a7e8317bcb 100644 --- a/internal/js/modules/k6/browser/browser/registry_test.go +++ b/internal/js/modules/k6/browser/browser/registry_test.go @@ -290,7 +290,7 @@ func TestBrowserRegistry(t *testing.T) { vu := k6test.NewVU(t) var cancel context.CancelFunc - vu.CtxField, cancel = context.WithCancel(vu.CtxField) //nolint:fatcontext + vu.CtxField, cancel = context.WithCancel(vu.CtxField) browserRegistry := newBrowserRegistry(context.Background(), vu, remoteRegistry, &pidRegistry{}, nil) vu.ActivateVU() diff --git a/internal/js/modules/k6/browser/common/browser_test.go b/internal/js/modules/k6/browser/common/browser_test.go index 2b103d50085..549f5200850 100644 --- a/internal/js/modules/k6/browser/common/browser_test.go +++ b/internal/js/modules/k6/browser/common/browser_test.go @@ -171,7 +171,7 @@ func TestBrowserNewPageInContext(t *testing.T) { } var cancel func() - tc.b.vuCtx, cancel = context.WithCancel(tc.b.vuCtx) //nolint:fatcontext + tc.b.vuCtx, cancel = context.WithCancel(tc.b.vuCtx) // let newPageInContext return a context cancelation error by canceling the context before // running the method. cancel() diff --git a/internal/js/modules/k6/browser/common/element_handle.go b/internal/js/modules/k6/browser/common/element_handle.go index 07228368404..f2a7a1d2b36 100644 --- a/internal/js/modules/k6/browser/common/element_handle.go +++ b/internal/js/modules/k6/browser/common/element_handle.go @@ -565,7 +565,7 @@ func (h *ElementHandle) selectOption(apiCtx context.Context, values []any) (any, forceCallable: true, returnByValue: false, } - result, err := h.evalWithScript(apiCtx, opts, fn, values) //nolint:asasalint + result, err := h.evalWithScript(apiCtx, opts, fn, values) if err != nil { return nil, err } diff --git a/internal/js/modules/k6/browser/storage/storage_test.go b/internal/js/modules/k6/browser/storage/storage_test.go index 253d15dd424..160046fba49 100644 --- a/internal/js/modules/k6/browser/storage/storage_test.go +++ b/internal/js/modules/k6/browser/storage/storage_test.go @@ -18,9 +18,7 @@ func TestDirMake(t *testing.T) { t.Run("dir_provided", func(t *testing.T) { t.Parallel() - dir, err := os.MkdirTemp("", "*") //nolint:forbidigo - require.NoError(t, err) - t.Cleanup(func() { _ = os.RemoveAll(dir) }) //nolint:forbidigo + dir := t.TempDir() var s Dir require.NoError(t, s.Make("", dir)) diff --git a/internal/js/modules/k6/browser/tests/browser_test.go b/internal/js/modules/k6/browser/tests/browser_test.go index ef01fe5845f..402f9ef2e3c 100644 --- a/internal/js/modules/k6/browser/tests/browser_test.go +++ b/internal/js/modules/k6/browser/tests/browser_test.go @@ -76,14 +76,7 @@ func TestBrowserNewContext(t *testing.T) { func TestTmpDirCleanup(t *testing.T) { t.Parallel() - tmpDirPath, err := os.MkdirTemp("./", "") //nolint:forbidigo - t.Cleanup( - func() { - err := os.RemoveAll(tmpDirPath) //nolint:forbidigo - require.NoError(t, err) - }, - ) - require.NoError(t, err) + tmpDirPath := t.TempDir() b := newTestBrowser( t, @@ -91,8 +84,7 @@ func TestTmpDirCleanup(t *testing.T) { withEnvLookup(env.ConstLookup("TMPDIR", tmpDirPath)), ) p := b.NewPage(nil) - err = p.Close() - require.NoError(t, err) + require.NoError(t, p.Close()) matches, err := filepath.Glob(filepath.Join(tmpDirPath, storage.K6BrowserDataDirPattern)) assert.NoError(t, err) @@ -119,14 +111,7 @@ func TestTmpDirCleanup(t *testing.T) { func TestTmpDirCleanupOnContextClose(t *testing.T) { t.Parallel() - tmpDirPath, err := os.MkdirTemp("./", "") //nolint:forbidigo - t.Cleanup( - func() { - err := os.RemoveAll(tmpDirPath) //nolint:forbidigo - require.NoError(t, err) - }, - ) - require.NoError(t, err) + tmpDirPath := t.TempDir() b := newTestBrowser( t, diff --git a/internal/js/modules/k6/experimental/fs/file.go b/internal/js/modules/k6/experimental/fs/file.go index b60ce81565c..48b4d7f2da6 100644 --- a/internal/js/modules/k6/experimental/fs/file.go +++ b/internal/js/modules/k6/experimental/fs/file.go @@ -82,7 +82,7 @@ var _ io.Reader = (*file)(nil) // // When using SeekModeStart, the offset must be positive. // Negative offsets are allowed when using `SeekModeCurrent` or `SeekModeEnd`. -func (f *file) Seek(offset int64, whence SeekMode) (int64, error) { +func (f *file) Seek(offset int64, whence SeekMode) (int64, error) { //nolint:govet startingOffset := f.offset.Load() newOffset := startingOffset diff --git a/internal/js/modules/k6/experimental/websockets/blob.go b/internal/js/modules/k6/experimental/websockets/blob.go index b9a2fc2f76c..8ef488da7a7 100644 --- a/internal/js/modules/k6/experimental/websockets/blob.go +++ b/internal/js/modules/k6/experimental/websockets/blob.go @@ -123,7 +123,7 @@ func (r *WebSocketsAPI) fillData(b *blob, blobParts []interface{}, call sobek.Co obj := call.Arguments[0].ToObject(rt).Get(strconv.FormatInt(int64(n), 10)).ToObject(rt) switch { case isDataView(obj, rt): - _, err = b.data.Write(obj.Get("buffer").Export().(sobek.ArrayBuffer).Bytes()) + _, err = b.data.Write(obj.Get("buffer").Export().(sobek.ArrayBuffer).Bytes()) //nolint:forcetypeassert case isBlob(obj, r.blobConstructor): _, err = b.data.Write(extractBytes(obj, rt)) default: diff --git a/internal/lib/testutils/httpmultibin/grpc_wrappers_testing/service.go b/internal/lib/testutils/httpmultibin/grpc_wrappers_testing/service.go index 92fe2acd29a..8549fb20ca5 100644 --- a/internal/lib/testutils/httpmultibin/grpc_wrappers_testing/service.go +++ b/internal/lib/testutils/httpmultibin/grpc_wrappers_testing/service.go @@ -12,15 +12,16 @@ import ( //go:generate protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative test.proto // Register registers a test service that could be used for the testing gRPC wrappers -func Register(r grpc.ServiceRegistrar) *service { //nolint:revive // this is a test service - s := &service{} +func Register(r grpc.ServiceRegistrar) *Service { + s := &Service{} RegisterServiceServer(r, s) return s } -type service struct { +// Service is the test service for different grpc values and how they are handled +type Service struct { UnimplementedServiceServer TestStringImplementation func(context.Context, *wrappers.StringValue) (*wrappers.StringValue, error) @@ -31,7 +32,8 @@ type service struct { TestStreamImplementation func(Service_TestStreamServer) error } -func (s *service) TestString(ctx context.Context, in *wrappers.StringValue) (*wrappers.StringValue, error) { +// TestString is getting and returning a string value +func (s *Service) TestString(ctx context.Context, in *wrappers.StringValue) (*wrappers.StringValue, error) { if s.TestStringImplementation != nil { return s.TestStringImplementation(ctx, in) } @@ -39,7 +41,8 @@ func (s *service) TestString(ctx context.Context, in *wrappers.StringValue) (*wr return s.UnimplementedServiceServer.TestString(ctx, in) } -func (s *service) TestInteger(ctx context.Context, in *wrappers.Int64Value) (*wrappers.Int64Value, error) { +// TestInteger is getting and returning a integer value +func (s *Service) TestInteger(ctx context.Context, in *wrappers.Int64Value) (*wrappers.Int64Value, error) { if s.TestIntegerImplementation != nil { return s.TestIntegerImplementation(ctx, in) } @@ -47,7 +50,8 @@ func (s *service) TestInteger(ctx context.Context, in *wrappers.Int64Value) (*wr return s.UnimplementedServiceServer.TestInteger(ctx, in) } -func (s *service) TestBoolean(ctx context.Context, in *wrappers.BoolValue) (*wrappers.BoolValue, error) { +// TestBoolean is getting and returning a boolean value +func (s *Service) TestBoolean(ctx context.Context, in *wrappers.BoolValue) (*wrappers.BoolValue, error) { if s.TestBooleanImplementation != nil { return s.TestBooleanImplementation(ctx, in) } @@ -55,7 +59,8 @@ func (s *service) TestBoolean(ctx context.Context, in *wrappers.BoolValue) (*wra return s.UnimplementedServiceServer.TestBoolean(ctx, in) } -func (s *service) TestDouble(ctx context.Context, in *wrappers.DoubleValue) (*wrappers.DoubleValue, error) { +// TestDouble is getting and returning a double value +func (s *Service) TestDouble(ctx context.Context, in *wrappers.DoubleValue) (*wrappers.DoubleValue, error) { if s.TestDoubleImplementation != nil { return s.TestDoubleImplementation(ctx, in) } @@ -63,7 +68,8 @@ func (s *service) TestDouble(ctx context.Context, in *wrappers.DoubleValue) (*wr return s.UnimplementedServiceServer.TestDouble(ctx, in) } -func (s *service) TestValue(ctx context.Context, in *_struct.Value) (*_struct.Value, error) { +// TestValue is getting and returning a generic value +func (s *Service) TestValue(ctx context.Context, in *_struct.Value) (*_struct.Value, error) { if s.TestValueImplementation != nil { return s.TestValueImplementation(ctx, in) } @@ -71,7 +77,8 @@ func (s *service) TestValue(ctx context.Context, in *_struct.Value) (*_struct.Va return s.UnimplementedServiceServer.TestValue(ctx, in) } -func (s *service) TestStream(stream Service_TestStreamServer) error { +// TestStream is testing a stream of values +func (s *Service) TestStream(stream Service_TestStreamServer) error { if s.TestStreamImplementation != nil { return s.TestStreamImplementation(stream) } diff --git a/metrics/builtin.go b/metrics/builtin.go index d05f2baf002..e6525370f9e 100644 --- a/metrics/builtin.go +++ b/metrics/builtin.go @@ -1,6 +1,5 @@ package metrics -//nolint:nolintlint // unfortunately it is having a false possitive //nolint:revive const ( VUsName = "vus"