Skip to content

Commit f07eb9f

Browse files
committed
Run golangci-lint on macOS and Windows; fix lint issues
Signed-off-by: Oleksandr Redko <[email protected]>
1 parent 7224ca4 commit f07eb9f

File tree

11 files changed

+38
-40
lines changed

11 files changed

+38
-40
lines changed

.github/workflows/test.yml

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@ jobs:
3939
sudo apt-get install -y protobuf-compiler
4040
- name: Verify generated files
4141
run: make install-tools generate check-generated
42-
- name: Run golangci-lint
43-
uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0
44-
with:
45-
version: v2.1.0
46-
args: --verbose
4742
- name: Run yamllint
4843
run: yamllint .
4944
- name: Install shellcheck
@@ -74,6 +69,26 @@ jobs:
7469
- name: Check license boilerplates
7570
run: ltag -t ./hack/ltag --check -v
7671

72+
lint-go:
73+
name: "Lint Go"
74+
timeout-minutes: 30
75+
strategy:
76+
matrix:
77+
runs-on: [ubuntu-24.04, macos-15-large, windows-2022-8-cores]
78+
runs-on: ${{ matrix.runs-on }}
79+
steps:
80+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
81+
with:
82+
fetch-depth: 1
83+
- uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
84+
with:
85+
go-version: 1.24.x
86+
- name: Run golangci-lint
87+
uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0
88+
with:
89+
version: v2.1.0
90+
args: --verbose
91+
7792
security:
7893
name: "Vulncheck"
7994
runs-on: ubuntu-24.04

.golangci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ issues:
147147
formatters:
148148
enable:
149149
- gci
150-
- gofmt
151150
- gofumpt
151+
- goimports
152152
settings:
153153
gci:
154154
sections:

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
@@ -39,6 +39,8 @@ const (
3939
StatusBroken Status = "Broken"
4040
StatusStopped Status = "Stopped"
4141
StatusRunning Status = "Running"
42+
43+
InstanceSSHAddress = "127.0.0.1"
4244
)
4345

4446
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
@@ -202,7 +202,6 @@ func (l *LimaVzDriver) RunGUI() error {
202202
if l.CanRunGUI() {
203203
return l.machine.StartGraphicApplication(1920, 1200)
204204
}
205-
//nolint:revive // error-strings
206205
return fmt.Errorf("RunGUI is not supported for the given driver '%s' and display '%s'", "vz", *l.Instance.Config.Video.Display)
207206
}
208207

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
@@ -152,10 +152,9 @@ func (l *LimaWslDriver) Start(ctx context.Context) (chan error, error) {
152152
return errCh, err
153153
}
154154

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

0 commit comments

Comments
 (0)