Skip to content

Commit

Permalink
Update golangci-lint to 1.64.6 and update code to conform
Browse files Browse the repository at this point in the history
  • Loading branch information
mstoykov committed Mar 7, 2025
1 parent ff5aa4c commit 0bc1359
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 42 deletions.
7 changes: 4 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -84,7 +86,6 @@ linters:
- errname
- errorlint
- exhaustive
- exportloopref
- fatcontext
- forbidigo
- forcetypeassert
Expand Down Expand Up @@ -125,13 +126,13 @@ linters:
- sqlclosecheck
- staticcheck
- stylecheck
- tenv
- tparallel
- typecheck
- unconvert
- unparam
- unused
- usestdlibvars
- usetesting
- wastedassign
- whitespace
fast: false
3 changes: 1 addition & 2 deletions internal/js/bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion internal/js/console_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion internal/js/modules/k6/browser/browser/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion internal/js/modules/k6/browser/common/browser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion internal/js/modules/k6/browser/common/element_handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 1 addition & 3 deletions internal/js/modules/k6/browser/storage/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
21 changes: 3 additions & 18 deletions internal/js/modules/k6/browser/tests/browser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,23 +76,15 @@ 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,
withSkipClose(),
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)
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion internal/js/modules/k6/experimental/fs/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion internal/js/modules/k6/experimental/websockets/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -31,47 +32,53 @@ 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)
}

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)
}

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)
}

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)
}

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)
}

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)
}
Expand Down
1 change: 0 additions & 1 deletion metrics/builtin.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package metrics

//nolint:nolintlint // unfortunately it is having a false possitive
//nolint:revive
const (
VUsName = "vus"
Expand Down

0 comments on commit 0bc1359

Please sign in to comment.