Skip to content

Commit

Permalink
Stopped nolintlint and gofmt from fighting each other
Browse files Browse the repository at this point in the history
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 golangci/golangci-lint#3110 (comment)
  • Loading branch information
EduardGomezEscandell committed Mar 7, 2023
1 parent d5fe5e8 commit 2b16802
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion backend_mock.go
Expand Up @@ -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)
}
4 changes: 2 additions & 2 deletions exec.go
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
}
Expand Down
4 changes: 2 additions & 2 deletions exec_test.go
Expand Up @@ -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)

Expand Down Expand Up @@ -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")
}
})
Expand Down
8 changes: 4 additions & 4 deletions main_test.go
Expand Up @@ -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()

Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion registration_test.go
Expand Up @@ -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()

Expand Down

0 comments on commit 2b16802

Please sign in to comment.