From ffb17b920ddc1db9f6701e1a3578af22ee35d046 Mon Sep 17 00:00:00 2001 From: EduardGomezEscandell Date: Mon, 6 Mar 2023 12:51:07 +0100 Subject: [PATCH] Stopped nolintlint and gofmt from fighting each other 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 --- backend_with_mock.go | 2 +- exec.go | 4 ++-- exec_test.go | 4 ++-- internal/flags/flags.go | 8 ++++---- main_test.go | 8 ++++---- registration_test.go | 2 +- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/backend_with_mock.go b/backend_with_mock.go index 84724172..2bd78f81 100644 --- a/backend_with_mock.go +++ b/backend_with_mock.go @@ -26,6 +26,6 @@ func selectBackend(ctx context.Context) interfaces.Backend { return windows.Backend{} } - //nolint: forcetypeassert // The panic is expected and welcome + //nolint:forcetypeassert // The panic is expected and welcome return v.(interfaces.Backend) } diff --git a/exec.go b/exec.go index 0529f539..bf45d705 100644 --- a/exec.go +++ b/exec.go @@ -145,7 +145,7 @@ func (c *Cmd) Start() (err error) { go func() { select { case <-c.ctx.Done(): - //nolint: errcheck // Mimicking behaviour from stdlib + //nolint:errcheck // Mimicking behaviour from stdlib c.Process.Kill() // We deviate from the stdlib: "context cancelled" is more useful than "exit code 1" c.ctxErr = c.ctx.Err() @@ -178,7 +178,7 @@ func (c *Cmd) Output() (out []byte, err error) { if err != nil && captureErr { target := &exec.ExitError{} if errors.As(err, &target) { - //nolint: forcetypeassert + //nolint:forcetypeassert // copied from stdlib. We know this to be true because it is set further up in this same function target.Stderr = c.Stderr.(*prefixSuffixSaver).Bytes() } diff --git a/exec_test.go b/exec_test.go index 344d01df..1c3f140a 100644 --- a/exec_test.go +++ b/exec_test.go @@ -612,7 +612,7 @@ print("Your text was", v) // - In the happy path (all checks pass) we'll have waited on the command already, so // this second wait is superfluous. // - If a check fails, we don't really care about any subsequent errors like this one. - defer cmd.Wait() //nolint: errcheck + defer cmd.Wait() //nolint:errcheck buffer := make([]byte, 1024) @@ -642,7 +642,7 @@ print("Your text was", v) require.NoError(t, err, "Unexpected error on command wait") if tc.readFrom == readFromPipe { - err = stdin.(io.WriteCloser).Close() //nolint: forcetypeassert + err = stdin.(io.WriteCloser).Close() //nolint:forcetypeassert require.NoError(t, err, "Failed to close stdin pipe multiple times") } }) diff --git a/internal/flags/flags.go b/internal/flags/flags.go index a4278e91..90a1309a 100644 --- a/internal/flags/flags.go +++ b/internal/flags/flags.go @@ -13,12 +13,12 @@ const ( // All nolints are regarding the use of UPPPER_CASE. NONE WslFlags = 0x0 - ENABLE_INTEROP WslFlags = 0x1 //nolint: revive - APPEND_NT_PATH WslFlags = 0x2 //nolint: revive - ENABLE_DRIVE_MOUNTING WslFlags = 0x4 //nolint: revive + ENABLE_INTEROP WslFlags = 0x1 //nolint:revive + APPEND_NT_PATH WslFlags = 0x2 //nolint:revive + ENABLE_DRIVE_MOUNTING WslFlags = 0x4 //nolint:revive // Per the conversation at https://github.com/microsoft/WSL-DistroLauncher/issues/96 // the information about version 1 or 2 is on the 4th bit of the flags, which is // currently referenced neither by the API nor the documentation. - Undocumented_WSL_VERSION WslFlags = 0x8 //nolint: revive + Undocumented_WSL_VERSION WslFlags = 0x8 //nolint:revive ) diff --git a/main_test.go b/main_test.go index 5934215a..83a1752b 100644 --- a/main_test.go +++ b/main_test.go @@ -86,7 +86,7 @@ func uniqueDistroName(t *testing.T) string { // newTestDistro creates and registers a new distro with a mangled name and adds it to list of distros to remove. // -//nolint: revive // No, I wont' put the context before the *testing.T. +//nolint:revive // No, I wont' put the context before the *testing.T. func newTestDistro(t *testing.T, ctx context.Context, rootfs string) wsl.Distro { t.Helper() @@ -183,7 +183,7 @@ func cleanUpWslInstance(distro wsl.Distro) error { return nil } cmd := fmt.Sprintf("$env:WSL_UTF8=1 ; wsl.exe --unregister %s", distro.Name()) - _, err := exec.Command("powershell.exe", "-command", cmd).CombinedOutput() //nolint: gosec + _, err := exec.Command("powershell.exe", "-command", cmd).CombinedOutput() //nolint:gosec if err != nil { return fmt.Errorf("failed to clean up test WSL distro %q: %v", distro.Name(), err) } @@ -256,7 +256,7 @@ func backUpDefaultDistro() (func(), error) { return func() {}, nil // No distros registered: no backup needed } restore := func() { - //nolint: gosec // G204: Subprocess launched with a potential tainted input or cmd arguments + //nolint:gosec // G204: Subprocess launched with a potential tainted input or cmd arguments // No threat of code injection, wsl.exe will only interpret this text as a distro name // and throw Wsl/Service/WSL_E_DISTRO_NOT_FOUND if it does not exist. out, err := exec.Command("wsl.exe", "--set-default", distro).CombinedOutput() @@ -289,7 +289,7 @@ func keepAwake(t *testing.T, ctx context.Context, d *wsl.Distro) context.CancelF return func() { cancel() - //nolint: errcheck + //nolint:errcheck // not checking error because it is guaranteed to fail: it can only // finish by being interrupted. This is the intended behaviour. cmd.Wait() diff --git a/registration_test.go b/registration_test.go index 83638fc7..b5fe0af9 100644 --- a/registration_test.go +++ b/registration_test.go @@ -165,7 +165,7 @@ func TestUnregister(t *testing.T) { // called in order to deallocate resources. You can call cancel multiple times without // adverse effect. // -//nolint: revive // No, I wont' put the context before the *testing.T. +//nolint:revive // No, I wont' put the context before the *testing.T. func wslShutdownTimeout(t *testing.T, ctx context.Context, timeout time.Duration) (cancel func()) { t.Helper()