diff --git a/.golangci.yml b/.golangci.yml index 2c0329178d9..9654f770a81 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -25,6 +25,7 @@ linters: - perfsprint - revive - staticcheck + - unconvert - unused - usetesting - whitespace diff --git a/pkg/imgutil/nativeimgutil/nativeimgutil.go b/pkg/imgutil/nativeimgutil/nativeimgutil.go index 910512d9a3d..3008ff376a0 100644 --- a/pkg/imgutil/nativeimgutil/nativeimgutil.go +++ b/pkg/imgutil/nativeimgutil/nativeimgutil.go @@ -163,7 +163,7 @@ func (n *NativeImageUtil) CreateDisk(disk string, size int64) error { } defer f.Close() roundedSize := roundUp(size) - return f.Truncate(int64(roundedSize)) + return f.Truncate(roundedSize) } // ConvertToRaw converts a disk image to raw format. diff --git a/pkg/store/instance_windows.go b/pkg/store/instance_windows.go index 4f7b317175a..084c44876ee 100644 --- a/pkg/store/instance_windows.go +++ b/pkg/store/instance_windows.go @@ -72,7 +72,7 @@ func GetWslStatus(instName string) (string, error) { "--verbose", }) if err != nil { - return "", fmt.Errorf("failed to run `wsl --list --verbose`, err: %w (out=%q)", err, string(out)) + return "", fmt.Errorf("failed to run `wsl --list --verbose`, err: %w (out=%q)", err, out) } if out == "" { @@ -80,9 +80,8 @@ func GetWslStatus(instName string) (string, error) { } // Check for edge cases first - outString := string(out) - if strings.Contains(outString, "Windows Subsystem for Linux has no installed distributions.") { - if strings.Contains(outString, "Wsl/WSL_E_DEFAULT_DISTRO_NOT_FOUND") { + if strings.Contains(out, "Windows Subsystem for Linux has no installed distributions.") { + if strings.Contains(out, "Wsl/WSL_E_DEFAULT_DISTRO_NOT_FOUND") { return StatusBroken, fmt.Errorf( "failed to read instance state for instance %q because no distro is installed,"+ "try running `wsl --install -d Ubuntu` and then re-running Lima", instName) @@ -96,7 +95,7 @@ func GetWslStatus(instName string) (string, error) { var instState string wslListColsRegex := regexp.MustCompile(`\s+`) // wsl --list --verbose may have different headers depending on localization, just split by line - for _, rows := range strings.Split(strings.ReplaceAll(string(out), "\r\n", "\n"), "\n") { + for _, rows := range strings.Split(strings.ReplaceAll(out, "\r\n", "\n"), "\n") { cols := wslListColsRegex.Split(strings.TrimSpace(rows), -1) nameIdx := 0 // '*' indicates default instance diff --git a/pkg/windows/process_windows.go b/pkg/windows/process_windows.go index 9c88bbaf36a..93cb760d8ad 100644 --- a/pkg/windows/process_windows.go +++ b/pkg/windows/process_windows.go @@ -29,7 +29,7 @@ func GetProcessCommandLine(name string) ([]string, error) { } var outJSON CommandLineJSON - if err = json.Unmarshal([]byte(out), &outJSON); err != nil { + if err = json.Unmarshal(out, &outJSON); err != nil { return nil, fmt.Errorf("failed to unmarshal %q as %T: %w", out, outJSON, err) } diff --git a/pkg/wsl2/vm_windows.go b/pkg/wsl2/vm_windows.go index 531de6c0116..0ee09bcae33 100644 --- a/pkg/wsl2/vm_windows.go +++ b/pkg/wsl2/vm_windows.go @@ -30,7 +30,7 @@ func startVM(ctx context.Context, distroName string) error { }, executil.WithContext(ctx)) if err != nil { return fmt.Errorf("failed to run `wsl.exe --distribution %s`: %w (out=%q)", - distroName, err, string(out)) + distroName, err, out) } return nil } @@ -48,7 +48,7 @@ func initVM(ctx context.Context, instanceDir, distroName string) error { }, executil.WithContext(ctx)) if err != nil { return fmt.Errorf("failed to run `wsl.exe --import %s %s %s`: %w (out=%q)", - distroName, instanceDir, baseDisk, err, string(out)) + distroName, instanceDir, baseDisk, err, out) } return nil } @@ -62,7 +62,7 @@ func stopVM(ctx context.Context, distroName string) error { }, executil.WithContext(ctx)) if err != nil { return fmt.Errorf("failed to run `wsl.exe --terminate %s`: %w (out=%q)", - distroName, err, string(out)) + distroName, err, out) } return nil } @@ -172,7 +172,7 @@ func unregisterVM(ctx context.Context, distroName string) error { }, executil.WithContext(ctx)) if err != nil { return fmt.Errorf("failed to run `wsl.exe --unregister %s`: %w (out=%q)", - distroName, err, string(out)) + distroName, err, out) } return nil }