Skip to content

chore: bump golangci-lint to v2#49870

Merged
thaJeztah merged 1 commit intomoby:masterfrom
mmorel-35:golangci-lint@v2
May 15, 2025
Merged

chore: bump golangci-lint to v2#49870
thaJeztah merged 1 commit intomoby:masterfrom
mmorel-35:golangci-lint@v2

Conversation

@mmorel-35
Copy link
Copy Markdown
Contributor

- What I did

bump golangci-lint to v2

- How I did it

use golangci-lint migrate from migration-guide and realign the result to make it as close as possible as the actual configuration

- How to verify it

Golangci-lint is still working and raising proper issues.

- Human readable description for the release notes

- A picture of a cute animal (not mandatory but encouraged)

No

@mmorel-35 mmorel-35 force-pushed the golangci-lint@v2 branch 8 times, most recently from 7e3d641 to f502b2e Compare April 25, 2025 20:15
@mmorel-35 mmorel-35 marked this pull request as ready for review April 25, 2025 20:27
@mmorel-35 mmorel-35 force-pushed the golangci-lint@v2 branch 2 times, most recently from b5c4481 to 2935a98 Compare April 25, 2025 20:37
Copy link
Copy Markdown
Contributor

@kolyshkin kolyshkin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a WIP, right?

Comment thread .golangci.yml
Comment thread Dockerfile
@mmorel-35 mmorel-35 force-pushed the golangci-lint@v2 branch 3 times, most recently from fe97b2d to e25d087 Compare April 26, 2025 06:32
Comment thread .golangci.yml
Comment on lines +166 to +159
checks:
- all
- -QF1001 # FIXME: Apply De Morgan’s law
- -QF1003 # FIXME: Convert if/else-if chain to tagged switch
- -QF1004 # FIXME: Use strings.ReplaceAll instead of strings.Replace with n == -1
- -QF1006 # FIXME: Lift if+break into loop condition
- -QF1007 # FIXME: Merge conditional assignment into variable declaration
- -QF1008 # FIXME: Omit embedded fields from selector expression
- -QF1011 # FIXME: Omit redundant type from variable declaration
- -QF1012 # FIXME: Use fmt.Fprintf(x, ...) instead of x.Write(fmt.Sprintf(...))
- -S1000 # FIXME: Use plain channel send or receive instead of single-case select
- -SA4006 # FIXME: A value assigned to a variable is never read before being overwritten. Forgotten error check or dead code?
- -ST1000 # FIXME: Incorrect or missing package comment
- -ST1003 # FIXME: Poorly chosen identifier
- -ST1005 # FIXME: Incorrectly formatted error string
- -ST1006 # FIXME: Poorly chosen receiver name
- -ST1015 # FIXME: A switch’s default case should be the first or last case
- -ST1016 # FIXME: Use consistent method receiver names
- -ST1017 # FIXME: Don’t use Yoda conditions
- -ST1019 # FIXME: Importing the same package multiple times
- -ST1020 # FIXME: The documentation of an exported function should start with the function’s name
- -ST1023 # FIXME: Redundant type in variable declaration

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recall there were at least 2 that we prefer not to enable; see https://github.com/moby/sys/blob/c9593b2d4e2ac2478a7d1e1cdaa08436a89ca079/.golangci.yml#L14-L20

Specifically QF1008 was too opinionated to apply as a general rule; see moby/sys#187 (comment)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you expect me to do here, just remove the FIXME part and keep the documentation part ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I was a bit brief, as I had to head out.

Yes, we should probably put those as "permanent" (without a "fixme"). That's not to say we won't revisit its suggestions where it makes sense, but those were a bit too opinionated to be used as a strict requirement.

As to our usual flow for these (none of this is a "hard rule", just a flow that worked well before)

  • Where possible, we make the changes to make the linters happy first; usually that's in a separate PR (or a couple PR's, depending).
  • Reason there is that in most cases, such fixes already apply, just that older linters may not have detected them.
  • Of course there's exceptions; sometimes newer linters became more "relaxed" (so some "nolint" comments becoming redundant); those can go in together with the PR that updates the linters, if removing them ahead of time would cause CI to fail).
  • 👆if there's many changes, I usually try to keep them in smaller commits (sometimes grouped by package), which can help if such changes would have to be backported to a release branch.
  • If there's new rules that result in an exceptionally large number of issues; for those it may indeed be good to add a global exclude, and depending on the changes, perhaps a tracking ticket (for cases where the linter is "correct", but the issues non critical, or requiring further investigation or discussion)
  • Depending on that discussion, we can decide to make an exception "permanent" (won't fix)

After the linting fixes are merged (which allows us to verify they look good, also on older linters), we can update the linters (that PR would only contain the updates required for updating the linter)

Copy link
Copy Markdown
Contributor Author

@mmorel-35 mmorel-35 Apr 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opened #49885

what is left concerning staticcheck would be

    staticcheck:
      checks:
        - all
        - -QF1008 # Omit embedded fields from selector expression
        - -S1000  # Use plain channel send or receive instead of single-case select
        - -SA4006 # A value assigned to a variable is never read before being overwritten. Forgotten error check or dead code?
        - -SA5011 # Possible nil pointer dereference
        - -ST1000 # Incorrect or missing package comment
        - -ST1003 # Poorly chosen identifier
        - -ST1005 # Incorrectly formatted error string
        - -ST1020 # The documentation of an exported function should start with the function’s name

@mmorel-35 mmorel-35 force-pushed the golangci-lint@v2 branch 2 times, most recently from a622d4c to 900cc9c Compare May 14, 2025 06:33
@mmorel-35
Copy link
Copy Markdown
Contributor Author

mmorel-35 commented May 14, 2025

Do you believe #49920 shall be adressed first to be able to enable nakedret ?

@thaJeztah
Copy link
Copy Markdown
Member

Do you believe #49920 shall be adressed first to be able to enable nakedret ?

If it's easy to add an exception for the files it hits (a temporary filter on path?) I'd be fine with keeping that as a follow-up; I'll see if others could have an eye on those changes.

Comment thread .golangci.yml Outdated
Comment thread .golangci.yml
Comment thread .golangci.yml
checks:
- all
- -QF1008 # Omit embedded fields from selector expression; https://staticcheck.dev/docs/checks/#QF1008
- -S1000 # Use plain channel send or receive instead of single-case select; https://staticcheck.dev/docs/checks/#S1000
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this one is only hit in a single location, which may be fixable, but probably fine for a follow-up (or I may have a quick look)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

☝️ I'm OK with addressing this one in a follow up if I didn't find time to look at the correct patch.

@thaJeztah thaJeztah added this to the 28.2.0 milestone May 14, 2025
@mmorel-35 mmorel-35 force-pushed the golangci-lint@v2 branch 3 times, most recently from c2a5900 to b6afa35 Compare May 14, 2025 16:08
Copy link
Copy Markdown
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM after the two redundant exclusions are removed (assuming CI is happy with that)

Comment thread .golangci.yml Outdated
Comment thread .golangci.yml
@mmorel-35
Copy link
Copy Markdown
Contributor Author

ST1005 has 158 issues, it is probably better to adress it later ?

@thaJeztah
Copy link
Copy Markdown
Member

Oh! Looks like my comment landed on the wrong line? 🙈

Comment thread .golangci.yml Outdated
Comment thread .golangci.yml Outdated
Comment thread .golangci.yml Outdated
Signed-off-by: Matthieu MOREL <[email protected]>
Copy link
Copy Markdown
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@thaJeztah thaJeztah merged commit 493662d into moby:master May 15, 2025
144 checks passed
@mmorel-35 mmorel-35 deleted the golangci-lint@v2 branch May 15, 2025 12:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants