From 4fcedf5b2a2af6f4af840edc6aa8ac0e5aaf8446 Mon Sep 17 00:00:00 2001 From: EduardGomezEscandell Date: Mon, 20 Mar 2023 13:49:05 +0100 Subject: [PATCH] Fix nolint ping-pong Nolintlint wants the //nolint directives without a leading space GoFmt wants them with a leading space, ... except if nolint has no space afterwards: // nolint:foo // <-- malformed //nolint :foo // <-- malformed //nolint: foo // <-- malformed //nolint:foo // <-- OK See https://github.com/golangci/golangci-lint/issues/3110#issuecomment-1219153237 --- .../internal/distros/database/database_test.go | 13 ++++--------- .../internal/distros/database/export_test.go | 3 +-- .../database/serializable_distro_test.go | 3 +-- .../internal/distros/distro/distro_test.go | 6 ++---- .../internal/distros/distro/export_test.go | 3 +-- .../internal/distros/task/task_test.go | 9 +++------ .../proservices/wslinstance/wslinstance.go | 2 +- .../proservices/wslinstance/wslinstance_test.go | 17 ++++++----------- windows-agent/internal/testutils/wsl.go | 2 +- windows-agent/internal/testutils/wsl_windows.go | 2 +- .../internal/systeminfo/systeminfo.go | 2 +- 11 files changed, 22 insertions(+), 40 deletions(-) diff --git a/windows-agent/internal/distros/database/database_test.go b/windows-agent/internal/distros/database/database_test.go index 9f4fabd78..fd590f8eb 100644 --- a/windows-agent/internal/distros/database/database_test.go +++ b/windows-agent/internal/distros/database/database_test.go @@ -31,8 +31,7 @@ const ( badDbFileContents ) -//nolint: tparallel -// Subtests are parallel but the test itself is not due to the calls to RegisterDistro. +//nolint:tparallel // Subtests are parallel but the test itself is not due to the calls to RegisterDistro. func TestNew(t *testing.T) { distro, guid := testutils.RegisterDistro(t, false) @@ -84,9 +83,7 @@ func TestNew(t *testing.T) { } } -// Subtests are parallel but the test itself is not due to the calls to RegisterDistro. -// -//nolint:tparallel +//nolint:tparallel // Subtests are parallel but the test itself is not due to the calls to RegisterDistro. func TestDatabaseGetAll(t *testing.T) { distro1, _ := testutils.RegisterDistro(t, false) distro2, _ := testutils.RegisterDistro(t, false) @@ -126,8 +123,7 @@ func TestDatabaseGetAll(t *testing.T) { } } -//nolint: tparallel -// Subtests are parallel but the test itself is not due to the calls to RegisterDistro. +//nolint:tparallel // Subtests are parallel but the test itself is not due to the calls to RegisterDistro. func TestDatabaseGet(t *testing.T) { registeredDistroInDB, registeredGUID := testutils.RegisterDistro(t, false) registeredDistroNotInDB, _ := testutils.RegisterDistro(t, false) @@ -176,8 +172,7 @@ func TestDatabaseGet(t *testing.T) { } } -//nolint: tparallel -// Subtests are parallel but the test itself is not due to the calls to RegisterDistro. +//nolint:tparallel // Subtests are parallel but the test itself is not due to the calls to RegisterDistro. func TestDatabaseDump(t *testing.T) { distro1, guid1 := testutils.RegisterDistro(t, false) distro2, guid2 := testutils.RegisterDistro(t, false) diff --git a/windows-agent/internal/distros/database/export_test.go b/windows-agent/internal/distros/database/export_test.go index 5fa2a03a2..a08dde668 100644 --- a/windows-agent/internal/distros/database/export_test.go +++ b/windows-agent/internal/distros/database/export_test.go @@ -11,8 +11,7 @@ func (in SerializableDistro) NewDistro(storageDir string) (*distro.Distro, error // NewSerializableDistro is a wrapper around newSerializableDistro so as to make it accessible to tests. // -//nolint: revive -// unexported-return false positive! SerializableDistro is exported, even if it is an alias to an unexported type. +//nolint:revive // unexported-return false positive! SerializableDistro is exported, even if it is an alias to an unexported type. func NewSerializableDistro(d *distro.Distro) SerializableDistro { return newSerializableDistro(d) } diff --git a/windows-agent/internal/distros/database/serializable_distro_test.go b/windows-agent/internal/distros/database/serializable_distro_test.go index cfeba74b3..514fe728d 100644 --- a/windows-agent/internal/distros/database/serializable_distro_test.go +++ b/windows-agent/internal/distros/database/serializable_distro_test.go @@ -68,8 +68,7 @@ func TestSerializableDistroMarshallUnmarshall(t *testing.T) { } } -//nolint: tparallel -// Subtests are parallel but the test itself is not due to the calls to RegisterDistro. +//nolint:tparallel // Subtests are parallel but the test itself is not due to the calls to RegisterDistro. func TestSerializableDistroNewDistro(t *testing.T) { registeredDistro, registeredGUID := testutils.RegisterDistro(t, false) unregisteredDistro, fakeGUID := testutils.NonRegisteredDistro(t) diff --git a/windows-agent/internal/distros/distro/distro_test.go b/windows-agent/internal/distros/distro/distro_test.go index 5bf00e2f9..a84ba9536 100644 --- a/windows-agent/internal/distros/distro/distro_test.go +++ b/windows-agent/internal/distros/distro/distro_test.go @@ -219,8 +219,7 @@ func TestKeepAwake(t *testing.T) { } } -//nolint: tparallel -// Subtests are parallel but the test itself is not due to the calls to RegisterDistro. +//nolint:tparallel // Subtests are parallel but the test itself is not due to the calls to RegisterDistro. func TestWorkerConstruction(t *testing.T) { distroName, _ := testutils.RegisterDistro(t, false) @@ -296,8 +295,7 @@ func TestInvalidateIdempotent(t *testing.T) { require.False(t, (*w).stopCalled, "worker Stop should not be called in subsequent invalidations") } -//nolint: tparallel -// Subtests are parallel but the test itself is not due to the calls to RegisterDistro. +//nolint:tparallel // Subtests are parallel but the test itself is not due to the calls to RegisterDistro. func TestWorkerWrappers(t *testing.T) { distroName, _ := testutils.RegisterDistro(t, false) diff --git a/windows-agent/internal/distros/distro/export_test.go b/windows-agent/internal/distros/distro/export_test.go index 35f38aadd..55d209e9a 100644 --- a/windows-agent/internal/distros/distro/export_test.go +++ b/windows-agent/internal/distros/distro/export_test.go @@ -29,8 +29,7 @@ type Identity = identity // GetIdentity returns a reference to the distro's identity. // -//nolint: revive -// False positive, Identity is exported. +//nolint:revive // False positive, Identity is exported. func (d *Distro) GetIdentity() *Identity { return &d.identity } diff --git a/windows-agent/internal/distros/task/task_test.go b/windows-agent/internal/distros/task/task_test.go index 359fcd43a..7ad8a24ae 100644 --- a/windows-agent/internal/distros/task/task_test.go +++ b/windows-agent/internal/distros/task/task_test.go @@ -35,8 +35,7 @@ func TestRegistry(t *testing.T) { require.ElementsMatch(t, want, got, "registry should contain only the registered tasks") } -//nolint: tparallel -// Cannot make test parallel because of BackupRegistry. +//nolint:tparallel // Cannot make test parallel because of BackupRegistry. func TestMarshal(t *testing.T) { task.BackupRegistry(t) task.Register[testTask]() @@ -69,8 +68,7 @@ func TestMarshal(t *testing.T) { } } -//nolint: tparallel -// Cannot make test parallel because of BackupRegistry. +//nolint:tparallel // Cannot make test parallel because of BackupRegistry. func TestUnmarshal(t *testing.T) { task.BackupRegistry(t) task.Register[testTask]() @@ -116,8 +114,7 @@ func TestUnmarshal(t *testing.T) { } } -//nolint: tparallel -// Cannot make test parallel because of BackupRegistry. +//nolint:tparallel // Cannot make test parallel because of BackupRegistry. func TestMarsallUnmarshall(t *testing.T) { task.BackupRegistry(t) task.Register[testTask]() diff --git a/windows-agent/internal/proservices/wslinstance/wslinstance.go b/windows-agent/internal/proservices/wslinstance/wslinstance.go index c7935c953..73c26b467 100644 --- a/windows-agent/internal/proservices/wslinstance/wslinstance.go +++ b/windows-agent/internal/proservices/wslinstance/wslinstance.go @@ -66,7 +66,7 @@ func (s *Service) Connected(stream agentapi.WSLInstance_ConnectedServer) error { return fmt.Errorf("connection from %q: %v", info.WslName, err) } - //nolint: errcheck // We don't care about this error because we're cleaning up + //nolint:errcheck // We don't care about this error because we're cleaning up defer d.SetConnection(nil) log.Debugf(context.TODO(), "Connection to Linux-side service established") diff --git a/windows-agent/internal/proservices/wslinstance/wslinstance_test.go b/windows-agent/internal/proservices/wslinstance/wslinstance_test.go index 55dadfbf5..d0b3f729a 100644 --- a/windows-agent/internal/proservices/wslinstance/wslinstance_test.go +++ b/windows-agent/internal/proservices/wslinstance/wslinstance_test.go @@ -75,8 +75,7 @@ func (w step) String() string { return fmt.Sprintf("Unknown when (%d)", int(w)) } -//nolint: tparallel -// Subtests are parallel but the test itself is not due to the calls to RegisterDistro. +//nolint:tparallel // Subtests are parallel but the test itself is not due to the calls to RegisterDistro. func TestConnected(t *testing.T) { distroName, _ := testutils.RegisterDistro(t, false) @@ -236,9 +235,9 @@ func TestConnected(t *testing.T) { // testLoggerInterceptor replaces the logging middleware by printing the return // error of Connected to the test Log. // -//nolint: thelper -// The logs would be reported to come from the entrails of the GRPC module. It's more helpful to reference this function to // see that it is the middleware reporting. +// +//nolint:thelper // The logs would be reported to come from the entrails of the GRPC module. It's more helpful to reference this function to func testLoggerInterceptor(t *testing.T) grpc.StreamServerInterceptor { return func(srv interface{}, stream grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error { if err := handler(srv, stream); err != nil { @@ -277,9 +276,7 @@ func (s *wrappedService) Connected(stream agentapi.WSLInstance_ConnectedServer) // - if ok is true, returnErr is the return value of Connected. // - if ok is false, the wait times out hence Connected has not returned yet. returnedErr is therefore not valid. // -//nolint: revive -// Returning the error as first argument is strange but it makes sense here, we mimic the -// (value, ok) return type of a map access. +//nolint:revive // Returning the error as first argument is strange but it makes sense here, we mimic the (value, ok) return type of a map access. func (s *wrappedService) wait(timeout time.Duration) (returnedErr error, connectedHasReturned bool) { select { case returnedErr = <-s.Errch: @@ -289,8 +286,7 @@ func (s *wrappedService) wait(timeout time.Duration) (returnedErr error, connect } } -//nolint: revive -// testing.T should go before context, I won't listen to anyone arguing the contrary. +//nolint:revive // testing.T should go before context, I won't listen to anyone arguing the contrary. func serveWSLInstance(t *testing.T, ctx context.Context, srv wrappedService) (server *grpc.Server, address string) { t.Helper() @@ -318,8 +314,7 @@ type wslDistroMock struct { // newWslDistroMock creates a wslDistroMock, establishing a connection to the control stream. // -//nolint: revive -// testing.T should go before context, regardless of what these linters say. +//nolint:revive // testing.T should go before context, regardless of what these linters say. func newWslDistroMock(t *testing.T, ctx context.Context, ctrlAddr string) (mock *wslDistroMock) { t.Helper() diff --git a/windows-agent/internal/testutils/wsl.go b/windows-agent/internal/testutils/wsl.go index ef5454637..0a1e993e9 100644 --- a/windows-agent/internal/testutils/wsl.go +++ b/windows-agent/internal/testutils/wsl.go @@ -33,7 +33,7 @@ func RandomDistroName(t *testing.T) (name string) { testFullNormalized := normalizeName(t, strings.ReplaceAll(t.Name(), "/", "--")) - //nolint: gosec // No need to be cryptographically secure + //nolint:gosec // No need to be cryptographically secure return fmt.Sprintf("%s_%s_%d", testDistroPrefix, testFullNormalized, rand.Uint64()) } diff --git a/windows-agent/internal/testutils/wsl_windows.go b/windows-agent/internal/testutils/wsl_windows.go index da26a8829..8ee97ca58 100644 --- a/windows-agent/internal/testutils/wsl_windows.go +++ b/windows-agent/internal/testutils/wsl_windows.go @@ -125,7 +125,7 @@ func powershellOutputf(t *testing.T, command string, args ...any) string { cmd := fmt.Sprintf(command, args...) - //nolint: gosec // This function is only used in tests so no arbitrary code execution here + //nolint:gosec // This function is only used in tests so no arbitrary code execution here out, err := exec.Command("powershell", "-Command", cmd).CombinedOutput() require.NoError(t, err, "Non-zero return code for command:\n%s\nOutput:%s", cmd, out) diff --git a/wsl-pro-service/internal/systeminfo/systeminfo.go b/wsl-pro-service/internal/systeminfo/systeminfo.go index 785b247cd..b07529395 100644 --- a/wsl-pro-service/internal/systeminfo/systeminfo.go +++ b/wsl-pro-service/internal/systeminfo/systeminfo.go @@ -47,7 +47,7 @@ func fillOsRelease(info *agentapi.DistroInfo) error { } var marshaller struct { - //nolint: revive + //nolint:revive // ini mapper is strict with naming, so we cannot rename Id -> ID as the linter suggests Id, VersionId, PrettyName string }