Skip to content

dev: rewrite linters Manager #4419

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 26 commits into from
Mar 2, 2024
Merged

Conversation

ldez
Copy link
Member

@ldez ldez commented Feb 26, 2024

I just put a log inside the methods used to build/load linters/plugins, and validate linters in the configuration.
You can see the problem easily.

Before the PR #4404:

$ go run ./cmd/golangci-lint run 
Build all plugins.
Build all linters.
Build all plugins.
Build all linters.
Validate EnabledDisabledLinters.
Build all linters.
Validate EnabledDisabledLinters.
Build all linters.
Build all linters.
Validate EnabledDisabledLinters.
Build all linters.
$
Build Count
all linters 6
all plugins 2
validate 3

After the PR #4404:

go run ./cmd/golangci-lint run 
Build all plugins.
Build all linters.
Validate EnabledDisabledLinters.
Build all linters.
Validate EnabledDisabledLinters.
Build all linters.
Build all linters.
Validate EnabledDisabledLinters.
Build all linters.
$
Build Count
all linters 5
all plugins 1
validate 3

With this PR:

$ go run ./cmd/golangci-lint run
Build all linters.
Build all plugins.
Validate EnabledDisabledLinters.
$
Build Count
all linters 1
all plugins 1
validate 1

This behavior has been here since nearly the beginning of golangci-lint but the problem has increased with time.

Summary of the execution after #4404, #4412, and this PR:

  • Set up logger.
  • Load the configuration from file and flags (config.Loader.Load).
  • Initiate the linter database based on the effective configuration (linterdb.NewManager).
    • Build the linters (internals and plugins) (linterdb.LinterBuilder.Build, linterdb.PluginBuilder.Build)
    • Validate configuration (linterdb.Validator.Validate)
  • Runs the analysis.

Everything is done once and only once.

The improvement of the performance is not high, but the impact on debugging and maintainability is huge!

Next Step

A proposal for a new flag option and a bit of cleaning.

@ldez ldez added enhancement New feature or improvement topic: cleanup Related to code, process, or doc cleanup labels Feb 26, 2024
@ldez ldez requested review from bombsimon and Antonboom February 26, 2024 23:58
@ldez ldez force-pushed the feat/rewrite-manager branch 2 times, most recently from 925b221 to 5737c95 Compare February 27, 2024 16:06
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.

Awesome stuff, thanks for all this @ldez

@ldez ldez force-pushed the feat/rewrite-manager branch from 9ddce62 to 4daab12 Compare February 28, 2024 22:34
@ldez
Copy link
Member Author

ldez commented Feb 28, 2024

Even if I'm impatient to merge this PR, we will wait a bit for feedback from @Antonboom

@ldez ldez force-pushed the feat/rewrite-manager branch from 4daab12 to 9d196f4 Compare February 29, 2024 02:31
@ldez ldez force-pushed the feat/rewrite-manager branch from d2a825e to 83c68d6 Compare March 2, 2024 13:04
Copy link
Contributor

@Antonboom Antonboom left a comment

Choose a reason for hiding this comment

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

No principal comments.
Thanks 🎉

}

if l.DisableAll {
if len(l.Enable) == 0 && len(l.Presets) == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

cosmetic: gocritic also highlights that linters were already enabled or disabled via presets

Copy link
Member Author

Choose a reason for hiding this comment

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

gocritic handles its own rules, not our linters or presets.

Copy link
Contributor

@Antonboom Antonboom Mar 3, 2024

Choose a reason for hiding this comment

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

of course, I meant checkers
just to do it for linters too, for analogy

Copy link
Member Author

Choose a reason for hiding this comment

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

So I don't understand what is your suggestion here.

@ldez ldez force-pushed the feat/rewrite-manager branch from 0a3a59f to ad6b6e3 Compare March 2, 2024 20:34
@ldez
Copy link
Member Author

ldez commented Mar 2, 2024

@bombsimon @Antonboom Be prepared because after this merge I will open 6 PRs (5 today and 1 later) 😸

Note: every time I want to add you both as reviewers I laugh because of your login: I put a bomb 💣 and boom 💥 🤣

@ldez ldez merged commit b14d05c into golangci:master Mar 2, 2024
@ldez ldez deleted the feat/rewrite-manager branch March 2, 2024 20:43
@ldez ldez mentioned this pull request Mar 2, 2024
@ldez ldez added this to the next milestone Mar 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or improvement topic: cleanup Related to code, process, or doc cleanup
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants