Skip to content

dev: handle linter major versions #5848

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 2, 2025

Conversation

ldez
Copy link
Member

@ldez ldez commented Jun 1, 2025

I tried several approaches, this one is the only one that provides something that works: the previous linter version will be deprecated, and the new one will have a suffix.

linters:
  enable:
    - foo # deprecated
    - foo_v2
  settings:
    foo: # deprecated
      a: 1
      b: 2
    foo_v2:
      a: 1
      d: 2

It will not be usable in every case of breaking changes, but it will work for all linters that create a major version of the module.

usage example:

	return goanalysis.
		NewLinterFromAnalyzer(analyzer).
		WithVersion(2).
		WithLoadMode(goanalysis.LoadModeTypesInfo)

A configuration migration suggestion can be added as a log.

@ldez ldez added the enhancement New feature or improvement label Jun 1, 2025
@ldez ldez requested a review from bombsimon June 1, 2025 09:09
Copy link
Member

@bombsimon bombsimon left a comment

Choose a reason for hiding this comment

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

I'm not sure I think this is a good approach, or I might be missing something. If we bump the version to WithVersion(2) we will try to deserialize the config to the new format, but this doesn't mean that the users' updated their config? So if a user upgrades golangci-lint to a new version that now uses a different version, that will have the same effect as just upgrading the version directly.

Or is the plan to add one new linter/call per major version? That would add duplication for every configuration and potential indefinite legacy. If this is the goal, wouldn't just add the new version as a new linter be the same without having to put that logic into golangci-lint, e.g. like we did with gomnd -> mnd?

If a version is potentially removed and only vX is left, you'd now have to configure <linter>_vX even though it's the only version which I think is a bit confusing.

There are lots of linters that are not on v1 so it will be hard to know when/why this is used. A linter can change behavior and draft new major releases but keep the same config, now they've diverged between upstream and golangci-lint

I'm not sure what a good alternative would be, but I think I'd rather release a version of golangci-lint warning about versions/configuration to-be-updated. Then the user can prepare for a breaking change without having to spend the time now just because they upgrade golangci-lint.

This approach is new too me so I'll give it some more thought but just want to ensure I understand the suggestion first.

@ldez
Copy link
Member Author

ldez commented Jun 1, 2025

The goal is to have one linter per major version.
The previous linter will be deprecated and will follow the classical linter deprecation flow.

@ldez ldez changed the title dev: handle linters major versions dev: handle linter major versions Jun 1, 2025
@ldez ldez added this to the v2-unreleased milestone Jun 2, 2025
@ldez ldez merged commit 6cd10a9 into golangci:main Jun 2, 2025
18 checks passed
@ldez ldez deleted the feat/linter-major-version branch June 2, 2025 19:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants