Skip to content

Config migration omits nakedret config when max-func-lines is set to 0 #5754

Closed
@chris-reeves

Description

@chris-reeves

Welcome

  • Yes, I'm using a binary release within 2 latest releases. Only such installations are supported.
  • Yes, I've searched similar issues on GitHub and didn't find any.
  • Yes, I've read the typecheck section of the FAQ.
  • Yes, I've tried with the standalone linter if available (e.g., gocritic, go vet, etc.).
  • I agree to follow this project's Code of Conduct

How did you install golangci-lint?

Other

Description of the problem

The following config fails to be migrated from v1 to v2 using the migrate command:

linters-settings:
  nakedret:
    max-func-lines: 0

as the nakedret config is missing from the migrated config.

For example:

linters-settings:
  nakedret:
    max-func-lines: 0
  other-linter:
    other-linter-setting: "foo"

becomes:

version: "2"
linters:
  settings:
    other-linter:
      other-linter-setting: "foo"

I've confirmed that the tests will fail if testdata/yaml/linters-settings_nakedret[.golden].yml are changed to specify 0 as the value for max-func-lines.

I tried tweaking the NakedretSettings struct in pkg/commands/internal/migrate/versiontwo/linters_settings.go to see whether this would resolve the issue (I realise this is an autogenerated file) but it does not. Basically, the resulting struct is indistinguishable from the zero value. This is a bit of an edge-case as this is the only config setting for this linter and 0 is a valid, non-default, value.

Version of golangci-lint

$ golangci-lint --version
golangci-lint has version 2.1.2 built with go1.24.2 from 00a561d on 2025-04-15T13:16:26Z

Configuration

linters-settings:
  nakedret:
    max-func-lines: 0

Go environment

$ go version
go version go1.24.2 darwin/arm64

Verbose output of running

$ golangci-lint migrate -v
INFO golangci-lint has version 2.1.2 built with go1.24.2 from 00a561d on 2025-04-15T13:16:26Z
INFO [config_reader] Config search paths: [./ /<path-to-repo> <redacted> /]
INFO [config_reader] Used config file .golangci.yml
INFO Validating v1 configuration file: /<path-to-repo>/.golangci.yml
INFO Saving the v1 configuration to: /<path-to-repo>/.golangci.bck.yml
WARN The configuration comments are not migrated.
WARN Details about the migration: https://golangci-lint.run/product/migration-guide/
INFO Migrating v1 configuration file: /<path-to-repo>/.golangci.yml
INFO Migration done: /<path-to-repo>/.golangci.yml
╭───────────────────────────────────────────────────────────────────────────╮
│                                                                           │
│                               We need you!                                │
│                                                                           │
│ Donations help fund the ongoing development and maintenance of this tool. │
│  If golangci-lint has been useful to you, please consider contributing.   │
│                                                                           │
│                  Donate now: https://donate.golangci.org                  │
│                                                                           │
╰───────────────────────────────────────────────────────────────────────────╯
$ echo $?
0

A minimal reproducible example or link to a public repository

.golangci.yml:

linters-settings:
  nakedret:
    max-func-lines: 0

then run golangci-lint migrate.

Validation

  • Yes, I've included all information above (version, config, etc.).

Supporter

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions