52 Commits
Author SHA1 Message Date
Jan Dubois 00c49d5cee Fix new lint findings from golangci-lint 2.15.0
errcheck v1.30.0 reports a bare receive from an error channel as an
unchecked error. Each receive it flagged waits for a process or server
to exit after Lima has stopped or killed it, so the error adds nothing;
discard it with "_ = <-ch".

But staticcheck's S1005 flags "_ = <-ch" as an unnecessary blank
assignment, so each spelling of the discard fails one of the two
linters. Disable S1005. It also flags blank identifiers in range loops,
such as "for _ = range", but gofmt's simplify step and revive's range
rule still catch those.

Signed-off-by: Jan Dubois <jan.dubois@suse.com>
2026-10-26 00:19:51 -07:00
Akihiro SudaandAnsuman Sahoo 89fe8b8f58 hack/tools/go.mod: github.com/golangci/golangci-lint/v2 v2.13.0
Co-authored-by: Ansuman Sahoo <anshumansahoo500@gmail.com>
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2026-08-21 04:27:15 +09:00
Oleksandr Redko d1a979c358 refactor: enable usestdlibvars linter
Signed-off-by: Oleksandr Redko <oleksandr.red+github@gmail.com>
2026-05-28 13:23:20 +03:00
Oleksandr Redko 6362ee37f3 refactor: Use slices.Sort instead of sort.Strings
Signed-off-by: Oleksandr Redko <oleksandr.red+github@gmail.com>
2026-01-22 13:38:50 +02:00
Jan Dubois de1571f501 lint: fix revive issues from golangci-lint 2.8.0
Add nolint directive for flag.Parse() in external driver server (the
Serve function is intended to be called from main). Add exclusion for
"api" package names in hostagent and guestagent.

Signed-off-by: Jan Dubois <jan.dubois@suse.com>
2026-01-15 19:09:35 -08:00
Oleksandr Redko 2c7c142fbe chore: simplify perfsprint linter configuration
Signed-off-by: Oleksandr Redko <oleksandr.red+github@gmail.com>
2025-11-21 19:23:43 +02:00
Oleksandr Redko 94c67ba6d6 refactor: fix modernize.stringsbuilder lint issues
Signed-off-by: Oleksandr Redko <oleksandr.red+github@gmail.com>
2025-11-20 16:51:17 +02:00
Oleksandr Redko e1c00dd18d refactor: fix modernize lint issues
Signed-off-by: Oleksandr Redko <oleksandr.red+github@gmail.com>
2025-11-18 12:55:55 +02:00
dependabot[bot] c290d4bd2a build(deps): bump github.com/golangci/golangci-lint/v2 in /hack/tools
Bumps [github.com/golangci/golangci-lint/v2](https://github.com/golangci/golangci-lint) from 2.5.0 to 2.6.0.
- [Release notes](https://github.com/golangci/golangci-lint/releases)
- [Changelog](https://github.com/golangci/golangci-lint/blob/main/CHANGELOG.md)
- [Commits](https://github.com/golangci/golangci-lint/compare/v2.5.0...v2.6.0)

---
updated-dependencies:
- dependency-name: github.com/golangci/golangci-lint/v2
  dependency-version: 2.6.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2025-10-30 10:45:59 +09:00
Oleksandr Redko f888f7acb2 Fix revive.package-directory-mismatch lint issues
Signed-off-by: Oleksandr Redko <oleksandr.red+github@gmail.com>
2025-10-16 18:39:16 +03:00
Oleksandr Redko a4482bb758 refactor: replace context.Background() with t.Context() in tests
Signed-off-by: Oleksandr Redko <oleksandr.red+github@gmail.com>
2025-08-20 15:55:24 +03:00
Akihiro Suda bd955e4d4c go.mod: github.com/lima-vm/lima/v2
The major version is now updated to highlight the introduction of the
pluggable VM driver framework.

See issue 3712

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2025-07-15 18:48:03 +09:00
Oleksandr Redko 8b7ba1e218 refactor: Fix staticcheck QF* issues
Signed-off-by: Oleksandr Redko <oleksandr.red+github@gmail.com>
2025-07-04 19:34:43 +03:00
Oleksandr Redko e88664dd04 chore: Enable unconvert linter
Signed-off-by: Oleksandr Redko <oleksandr.red+github@gmail.com>
2025-07-03 14:10:15 +03:00
Oleksandr Redko f915900d38 chore: Update golangci-lint from v2.1 to v2.2
Signed-off-by: Oleksandr Redko <oleksandr.red+github@gmail.com>
2025-07-01 18:59:38 +03:00
Oleksandr Redko e6216df5b3 Split imports into sections: std, default, local
Signed-off-by: Oleksandr Redko <oleksandr.red+github@gmail.com>
2025-05-26 14:46:55 +03:00
Oleksandr Redko 01b435a426 Enable usetesting linter
Signed-off-by: Oleksandr Redko <oleksandr.red+github@gmail.com>
2025-04-24 17:35:13 +03:00
Oleksandr Redko 2fa2dc8830 refactor: Simplify code with gopls modernize
Signed-off-by: Oleksandr Redko <oleksandr.red+github@gmail.com>
2025-04-02 17:01:00 +03:00
Oleksandr Redko cad433e25e Upgrade golangci-lint to v2
Signed-off-by: Oleksandr Redko <oleksandr.red+github@gmail.com>
2025-03-24 22:42:05 +02:00
Oleksandr Redko 8b1b130fb5 refactor: use math/rand/v2 instead of math/rand
Signed-off-by: Oleksandr Redko <oleksandr.red+github@gmail.com>
2025-01-31 19:03:39 +02:00
Oleksandr Redko f6e9125158 refactor: replace interface{} with any
Signed-off-by: Oleksandr Redko <oleksandr.red+github@gmail.com>
2025-01-14 14:21:36 +02:00
Pascal Bourdier 60baa9e8b7 review
Signed-off-by: Pascal Bourdier <pascal.bourdier@gmail.com>
2024-12-19 18:53:20 +01:00
Pascal Bourdier 639ec84e56 add comment & ignore .idea dir
Signed-off-by: Pascal Bourdier <pascal.bourdier@gmail.com>
2024-12-19 15:33:48 +01:00
Pascal Bourdier b0c1bdb6a5 ci: raise timeout for golangci
to avoid it locally:
```
ERRO Running error: context loading failed: failed to load packages: failed to load packages: failed to load with go/packages: context deadline exceeded
ERRO Timeout exceeded: try increasing it by passing --timeout option
```

Signed-off-by: Pascal Bourdier <pascal.bourdier@gmail.com>
2024-12-19 14:53:04 +01:00
Jan Dubois c7927bd242 Merge pull request #2950 from alexandear/ci-cleanup-golangci-yml
ci: cleanup .golangci.yml by removing deprecated linters
2024-11-29 08:44:05 -08:00
Oleksandr Redko 63cc564f14 refactor: replace fmt.Errorf with errors.New
Signed-off-by: Oleksandr Redko <oleksandr.red+github@gmail.com>
2024-11-29 17:28:25 +02:00
Oleksandr Redko 90780a4695 ci: cleanup .golangci.yml by removing deprecated linters
Signed-off-by: Oleksandr Redko <oleksandr.red+github@gmail.com>
2024-11-29 16:04:53 +02:00
Oleksandr Redko 8a665d1a7d refactor: remove useless copy loop var
Signed-off-by: Oleksandr Redko <oleksandr.red+github@gmail.com>
2024-11-11 19:37:38 +02:00
Oleksandr Redko e4073addb5 test: refactor to use assert pkg instead of t.Fatal
Signed-off-by: Oleksandr Redko <oleksandr.red+github@gmail.com>
2024-11-08 14:05:40 +02:00
Oleksandr Redko b1d06193ef downloader: simplify tests
Signed-off-by: Oleksandr Redko <oleksandr.red+github@gmail.com>
2024-11-07 23:10:28 +02:00
Oleksandr Redko ad57ef987e refactor: replace fmt.Print with an explicit out to Stdout
Signed-off-by: Oleksandr Redko <oleksandr.red+github@gmail.com>
2024-11-04 22:43:29 +02:00
Jan Dubois c77bfa2883 Make guest username, uid, home directory configurable
Also disallows the "admin" username by default (because it is a builtin
user in Ubuntu), but can be overridden by setting it explicitly in lima.yaml.

Signed-off-by: Jan Dubois <jan.dubois@suse.com>
2024-11-01 17:00:45 -07:00
Oleksandr Redko 261953610a Use "context" instead of "golang.org/x/net/context"
Signed-off-by: Oleksandr Redko <oleksandr.red+github@gmail.com>
2024-09-12 23:14:35 +03:00
Oleksandr Redko 2db1cf3804 Uncapitalize error messages; enable revive.error-strings
Signed-off-by: Oleksandr Redko <oleksandr.red+github@gmail.com>
2024-07-24 18:58:25 +03:00
Oleksandr Redko fc5556e121 Fix function and package comments
Signed-off-by: Oleksandr Redko <oleksandr.red+github@gmail.com>
2024-07-23 14:23:53 +03:00
Oleksandr Redko c322721ae2 Refactor to use switch instead of if-else chain
Signed-off-by: Oleksandr Redko <oleksandr.red+github@gmail.com>
2024-07-05 18:06:41 +03:00
Oleksandr Redko 597c276288 cmd/limactl: return error instead of calling os.Exit
Signed-off-by: Oleksandr Redko <oleksandr.red+github@gmail.com>
2024-06-25 13:05:58 +03:00
Oleksandr Redko 5abbf92c99 Enable godot linter; append dot at the end of comments
Signed-off-by: Oleksandr Redko <oleksandr.red+github@gmail.com>
2024-06-18 12:10:13 +03:00
Oleksandr Redko 04c7533449 Enable noctx linter and fix up issues
Signed-off-by: Oleksandr Redko <Oleksandr_Redko@epam.com>
2024-01-24 20:59:46 +02:00
Oleksandr Redko 0ac3843cd6 Enable errorlint and fix up issues
Signed-off-by: Oleksandr Redko <Oleksandr_Redko@epam.com>
2024-01-10 18:11:02 +02:00
Oleksandr Redko 7b163fb1a7 Enable gocritic linter and fix up issues
Signed-off-by: Oleksandr Redko <Oleksandr_Redko@epam.com>
2023-12-15 11:53:25 +02:00
Oleksandr Redko 966d9182e4 Enable errcheck linter; fix lint issues
Signed-off-by: Oleksandr Redko <Oleksandr_Redko@epam.com>
2023-11-02 12:48:38 +02:00
Oleksandr Redko 975dc17afb textutil,dns: enable and fix dupword lint issues
Signed-off-by: Oleksandr Redko <Oleksandr_Redko@epam.com>
2023-11-01 23:06:22 +02:00
Oleksandr Redko 5085191dbc ci: enable gofumpt, whitespace linters
Signed-off-by: Oleksandr Redko <Oleksandr_Redko@epam.com>
2023-10-30 12:55:32 +02:00
Oleksandr Redko 7fffa9df9a Add parseUidGid, formatUidGid functions
Signed-off-by: Oleksandr Redko <Oleksandr_Redko@epam.com>
2023-10-27 13:15:06 +03:00
Oleksandr Redko bf2c37f35c Enable and fix nolintlint,bodyclose,gosimple linters
Signed-off-by: Oleksandr Redko <Oleksandr_Redko@epam.com>
2023-10-25 12:26:51 +03:00
Akihiro Suda d329e4965b .golangci.yml: enable staticcheck
```
pkg/editutil/editutil.go:55:17: unused-parameter: parameter 'name' seems to be unused, consider removing or renaming it as _ (revive)
func OpenEditor(name string, content []byte, hdr string) ([]byte, error) {
                ^
pkg/downloader/downloader.go:480:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
        if err := os.Rename(localPathTmp, localPath); err != nil {
                return err
        }
pkg/guestagent/api/server/server.go:19:50: unused-parameter: parameter 'r' seems to be unused, consider removing or renaming it as _ (revive)
func (b *Backend) onError(w http.ResponseWriter, r *http.Request, err error, ec int) {
                                                 ^
pkg/cidata/cidata_test.go:16:19: unused-parameter: parameter 'host' seems to be unused, consider removing or renaming it as _ (revive)
func fakeLookupIP(host string) []net.IP {
                  ^
pkg/driver/driver.go:82:63: unused-parameter: parameter 'password' seems to be unused, consider removing or renaming it as _ (revive)
func (d *BaseDriver) ChangeDisplayPassword(_ context.Context, password string) error {
                                                              ^
pkg/networks/usernet/recoincile.go:86:4: if-return: redundant if ...; err != nil check, just return error instead. (revive)
                        if err := cmd.Start(); err != nil {
                                return err
                        }
pkg/networks/reconcile/reconcile.go:152:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
        if err := cmd.Start(); err != nil {
                return err
        }
pkg/qemu/qemu_driver.go:144:44: unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
func (l *LimaQemuDriver) changeVNCPassword(ctx context.Context, password string) error {
                                           ^
pkg/qemu/qemu_driver.go:166:44: unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
func (l *LimaQemuDriver) getVNCDisplayPort(ctx context.Context) (string, error) {
                                           ^
pkg/qemu/qemu_driver.go:269:41: unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
func (l *LimaQemuDriver) DeleteSnapshot(ctx context.Context, tag string) error {
                                        ^
pkg/hostagent/api/server/server.go:17:50: unused-parameter: parameter 'r' seems to be unused, consider removing or renaming it as _ (revive)
func (b *Backend) onError(w http.ResponseWriter, r *http.Request, err error, ec int) {
                                                 ^
cmd/limactl/completion.go:8:32: unused-parameter: parameter 'cmd' seems to be unused, consider removing or renaming it as _ (revive)
func bashCompleteInstanceNames(cmd *cobra.Command) ([]string, cobra.ShellCompDirective) {
                               ^
cmd/limactl/edit.go:141:43: unused-parameter: parameter 'args' seems to be unused, consider removing or renaming it as _ (revive)
func editBashComplete(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
                                          ^
cmd/limactl/debug.go:64:6: empty-block: this block is empty, you can remove it (revive)
        for {
        }
cmd/limactl/snapshot.go:187:47: unused-parameter: parameter 'args' seems to be unused, consider removing or renaming it as _ (revive)
func snapshotBashComplete(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
                                              ^
cmd/limactl/factory-reset.go:25:25: unused-parameter: parameter 'cmd' seems to be unused, consider removing or renaming it as _ (revive)
func factoryResetAction(cmd *cobra.Command, args []string) error {
                        ^
cmd/limactl/validate.go:23:21: unused-parameter: parameter 'cmd' seems to be unused, consider removing or renaming it as _ (revive)
func validateAction(cmd *cobra.Command, args []string) error {
                    ^
cmd/limactl/factory-reset.go:59:51: unused-parameter: parameter 'args' seems to be unused, consider removing or renaming it as _ (revive)
func factoryResetBashComplete(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
                                                  ^
pkg/iso9660util/iso9660util.go:5:2: SA1019: "io/ioutil" has been deprecated since Go 1.19: As of Go 1.16, the same functionality is now provided by package io or package os, and those implementations should be preferred in new code. See the specific function documentation for details. (staticcheck)
        "io/ioutil"
        ^
pkg/downloader/downloader_test.go:4:2: SA1019: "io/ioutil" has been deprecated since Go 1.19: As of Go 1.16, the same functionality is now provided by package io or package os, and those implementations should be preferred in new code. See the specific function documentation for details. (staticcheck)
        "io/ioutil"
        ^
pkg/vz/vz_driver_darwin.go:174:11: SA1015: using time.Tick leaks the underlying ticker, consider using it only in endless functions, tests and the main package, and use time.NewTicker here (staticcheck)
                tick := time.Tick(500 * time.Millisecond)
                        ^
pkg/networks/usernet/client.go:33:10: SA1015: using time.Tick leaks the underlying ticker, consider using it only in endless functions, tests and the main package, and use time.NewTicker here (staticcheck)
        tick := time.Tick(500 * time.Millisecond)
                ^
pkg/vz/vm_darwin.go:88:6: SA5003: defers in this infinite loop will never run (staticcheck)
                                        defer os.RemoveAll(pidFile)
                                        ^
```

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2023-06-03 23:43:45 +09:00
Akihiro Suda 7da983273f CI: update golangci-lint to v1.53.1
depguard is now silenced

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2023-06-03 23:26:05 +09:00
Akihiro Suda e5a79f13f0 golangci-lint: enable revive
The `revive` linter was failing with the following errors:

```
pkg/osutil/user.go:19:2: var-naming: struct field Uid should be UID (revive)
        Uid   uint32
        ^
pkg/osutil/user.go:79:2: var-naming: const fallbackUid should be fallbackUID (revive)
        fallbackUid  = 1000
        ^
pkg/osutil/osutil_others.go:16:2: var-naming: struct field Uid should be UID (revive)
        Uid uint32
        ^
cmd/limactl/start.go:178:10: indent-error-flow: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary) (revive)
                } else {
                        if !errors.Is(err, os.ErrNotExist) {
                                return nil, err
                        }
                        if arg != "" && arg != DefaultInstanceName {
                                logrus.Infof("Creating an instance %q from template://default (Not from template://%s)", st.instName, st.instName)
                                logrus.Warnf("This form is deprecated. Use `limactl start --name=%s template://default` instead", st.instName)
                        }
                        // Read the default template for creating a new instance
                        st.yBytes, err = readDefaultTemplate()
                        if err != nil {
                                return nil, err
                        }
                }
pkg/hostagent/dns/dns_test.go:70:5: var-naming: don't use underscores in Go names; var regex_match should be regexMatch (revive)
                                regex_match := func(value string, pattern string) cmp.Comparison {
                                ^
pkg/networks/reconcile/reconcile.go:112:51: context-as-argument: context.Context should be the first parameter of a function (revive)
func startDaemon(config *networks.NetworksConfig, ctx context.Context, name, daemon string) error {
                                                  ^
pkg/networks/reconcile/reconcile.go:176:52: context-as-argument: context.Context should be the first parameter of a function (revive)
func startNetwork(config *networks.NetworksConfig, ctx context.Context, name string) error {
                                                   ^
pkg/networks/networks.go:5:6: exported: type name will be used as networks.NetworksConfig by other packages, and that stutters; consider calling this Config (revive)
type NetworksConfig struct {
     ^
pkg/networks/sudoers.go:84:10: indent-error-flow: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary) (revive)
                } else {
                        return fmt.Errorf("passwordLessSudo error: %w", err)
                }
pkg/networks/sudoers.go:96:11: indent-error-flow: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary) (revive)
                        } else {
                                logrus.Debugf("%q does not exist; passwordLessSudo error: %s", sudoersFile, err)
                        }
```

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2022-09-26 10:10:28 +09:00
Akihiro Suda 5efc3f1bc6 CI: update golangci-lint (1.49)
`varcheck`, `deadcode`, and `structcheck` are replaced by `unused`

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2022-09-26 10:10:28 +09:00