Skip to content

Commit 34584e0

Browse files
committed
Run golangci-lint on MacOS and Windows; fix lint issues
Signed-off-by: Oleksandr Redko <[email protected]>
1 parent 074eed6 commit 34584e0

File tree

10 files changed

+27
-34
lines changed

10 files changed

+27
-34
lines changed

.github/workflows/test.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,11 @@ jobs:
163163
go-version: 1.24.x
164164
- name: Unit tests
165165
run: go test -v ./...
166+
- name: Run golangci-lint
167+
uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0
168+
with:
169+
version: v2.1.0
170+
args: --verbose
166171
- name: Make
167172
run: make
168173
- name: Integration tests (WSL2, Windows host)
@@ -190,6 +195,11 @@ jobs:
190195
go-version: 1.24.x
191196
- name: Unit tests
192197
run: go test -v ./...
198+
- name: Run golangci-lint
199+
uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0
200+
with:
201+
version: v2.1.0
202+
args: --verbose
193203
- name: Make
194204
run: make
195205
- name: Install

pkg/hostagent/hostagent.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -313,11 +313,7 @@ func (a *HostAgent) Run(ctx context.Context) error {
313313

314314
// WSL instance SSH address isn't known until after VM start
315315
if *a.instConfig.VMType == limayaml.WSL2 {
316-
sshAddr, err := store.GetSSHAddress(a.instName)
317-
if err != nil {
318-
return err
319-
}
320-
a.instSSHAddress = sshAddr
316+
a.instSSHAddress = store.InstanceSSHAddress
321317
}
322318

323319
if a.instConfig.Video.Display != nil && *a.instConfig.Video.Display == "vnc" {

pkg/lockutil/lockutil_windows.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929
"github.com/sirupsen/logrus"
3030
)
3131

32-
// LockFile modified from https://github.com/boltdb/bolt/blob/v1.3.1/bolt_windows.go using MIT
32+
// LockFile modified from https://github.com/boltdb/bolt/blob/v1.3.1/bolt_windows.go using MIT.
3333
var (
3434
modkernel32 = syscall.NewLazyDLL("kernel32.dll")
3535
procLockFileEx = modkernel32.NewProc("LockFileEx")
@@ -38,8 +38,8 @@ var (
3838

3939
const (
4040
// see https://msdn.microsoft.com/en-us/library/windows/desktop/aa365203(v=vs.85).aspx
41-
LOCKFILE_EXCLUSIVE_LOCK = 0x00000002
42-
LOCKFILE_FAIL_IMMEDIATELY = 0x00000001
41+
LOCKFILE_EXCLUSIVE_LOCK = 0x00000002 //nolint:revive,staticcheck // var-naming: it's ok to use ALL_CAPS here
42+
LOCKFILE_FAIL_IMMEDIATELY = 0x00000001 //nolint:revive,staticcheck // var-naming: it's ok to use ALL_CAPS here
4343
)
4444

4545
func WithDirLock(dir string, fn func() error) error {

pkg/osutil/osutil_windows.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
// UnixPathMax is the value of UNIX_PATH_MAX.
1717
const UnixPathMax = 108
1818

19-
// Stat is a selection of syscall.Stat_t
19+
// Stat is a selection of syscall.Stat_t.
2020
type Stat struct {
2121
Uid uint32
2222
Gid uint32
@@ -38,8 +38,8 @@ func SysKill(pid int, _ Signal) error {
3838
return windows.GenerateConsoleCtrlEvent(syscall.CTRL_BREAK_EVENT, uint32(pid))
3939
}
4040

41-
func Dup2(oldfd int, newfd syscall.Handle) (err error) {
42-
return fmt.Errorf("unimplemented")
41+
func Dup2(_ int, _ syscall.Handle) error {
42+
return errors.New("unimplemented")
4343
}
4444

4545
func SignalName(sig os.Signal) string {
@@ -53,6 +53,6 @@ func SignalName(sig os.Signal) string {
5353
}
5454
}
5555

56-
func Sysctl(name string) (string, error) {
56+
func Sysctl(_ string) (string, error) {
5757
return "", errors.New("sysctl: unimplemented on Windows")
5858
}

pkg/store/instance.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ const (
3838
StatusBroken Status = "Broken"
3939
StatusStopped Status = "Stopped"
4040
StatusRunning Status = "Running"
41+
42+
InstanceSSHAddress = "127.0.0.1"
4143
)
4244

4345
type Instance struct {

pkg/store/instance_unix.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,3 @@ import "github.com/lima-vm/lima/pkg/limayaml"
1010
func inspectStatus(instDir string, inst *Instance, y *limayaml.LimaYAML) {
1111
inspectStatusWithPIDFiles(instDir, inst, y)
1212
}
13-
14-
func GetSSHAddress(_ string) (string, error) {
15-
return "127.0.0.1", nil
16-
}

pkg/store/instance_windows.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,7 @@ func inspectStatus(instDir string, inst *Instance, y *limayaml.LimaYAML) {
2525
inst.SSHLocalPort = 22
2626

2727
if inst.Status == StatusRunning {
28-
sshAddr, err := GetSSHAddress(inst.Name)
29-
if err == nil {
30-
inst.SSHAddress = sshAddr
31-
} else {
32-
inst.Errors = append(inst.Errors, err)
33-
}
28+
inst.SSHAddress = InstanceSSHAddress
3429
}
3530
} else {
3631
inspectStatusWithPIDFiles(instDir, inst, y)
@@ -75,7 +70,7 @@ func GetWslStatus(instName string) (string, error) {
7570
return "", fmt.Errorf("failed to run `wsl --list --verbose`, err: %w (out=%q)", err, string(out))
7671
}
7772

78-
if len(out) == 0 {
73+
if out == "" {
7974
return StatusBroken, fmt.Errorf("failed to read instance state for instance %q, try running `wsl --list --verbose` to debug, err: %w", instName, err)
8075
}
8176

@@ -115,7 +110,3 @@ func GetWslStatus(instName string) (string, error) {
115110

116111
return instState, nil
117112
}
118-
119-
func GetSSHAddress(instName string) (string, error) {
120-
return "127.0.0.1", nil
121-
}

pkg/vz/vz_driver_darwin.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,6 @@ func (l *LimaVzDriver) RunGUI() error {
203203
if l.CanRunGUI() {
204204
return l.machine.StartGraphicApplication(1920, 1200)
205205
}
206-
//nolint:revive // error-strings
207206
return fmt.Errorf("RunGUI is not supported for the given driver '%s' and display '%s'", "vz", *l.Instance.Config.Video.Display)
208207
}
209208

pkg/windows/registry_windows.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ func GetDistroID(name string) (string, error) {
146146
}
147147

148148
// GetRandomFreeVSockPort gets a list of all registered VSock ports and returns a non-registered port.
149-
func GetRandomFreeVSockPort(min, max int) (int, error) {
149+
func GetRandomFreeVSockPort(minPort, maxPort int) (int, error) {
150150
rootKey, err := getGuestCommunicationServicesKey(false)
151151
if err != nil {
152152
return 0, err
@@ -160,18 +160,18 @@ func GetRandomFreeVSockPort(min, max int) (int, error) {
160160

161161
type pair struct{ v, offset int }
162162
tree := make([]pair, 1, len(used)+1)
163-
tree[0] = pair{0, min}
163+
tree[0] = pair{0, minPort}
164164

165165
sort.Ints(used)
166166
for i, v := range used {
167167
if tree[len(tree)-1].v+tree[len(tree)-1].offset == v {
168168
tree[len(tree)-1].offset++
169169
} else {
170-
tree = append(tree, pair{v - min - i, min + i + 1})
170+
tree = append(tree, pair{v - minPort - i, minPort + i + 1})
171171
}
172172
}
173173

174-
v := rand.IntN(max - min + 1 - len(used))
174+
v := rand.IntN(maxPort - minPort + 1 - len(used))
175175

176176
for len(tree) > 1 {
177177
m := len(tree) / 2

pkg/wsl2/wsl_driver_windows.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,9 @@ func (l *LimaWslDriver) Start(ctx context.Context) (chan error, error) {
151151
return errCh, err
152152
}
153153

154-
// Requires WSLg, which requires specific version of WSL2 to be installed.
154+
// CanRunGUI requires WSLg, which requires specific version of WSL2 to be installed.
155155
// TODO: Add check and add support for WSLg (instead of VNC) to hostagent.
156156
func (l *LimaWslDriver) CanRunGUI() bool {
157-
// return *l.InstConfig.Video.Display == "wsl"
158157
return false
159158
}
160159

0 commit comments

Comments
 (0)