Skip to content
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

plugin: allow to use settings for plugins #3887

Merged
merged 10 commits into from Jun 15, 2023

Conversation

ldez
Copy link
Member

@ldez ldez commented Jun 4, 2023

I want to introduce a new plugin contract that allow to pass settings to the plugin.

The previous contract based on AnalyzerPlugin interface still works: first we look for the New function and if don't find the right symbol we fallback to the AnalyzerPlugin interface.

Fixes #1512


To test the PR:

  1. Create the golangci-lint binary from this PR:
    make build
  2. Clone and checkout the plugin test branch:
    git clone git@github.com:golangci/example-plugin-linter.git
    git switch feat/new-plugin-signature
  3. Copy the configuration:
    cp .golangci.example.yml .golangci.yml
  4. Build and run the plugin:
    go build -buildmode=plugin plugin/example.go 
    ./golangci-lint run ./testdata/src/testlintdata/todo

@ldez ldez added enhancement New feature or improvement linter: custom About custom/private linters labels Jun 4, 2023
@ldez ldez force-pushed the feat/clean-custom-plugin branch from d828ce1 to bc88c72 Compare June 4, 2023 14:06
@ldez
Copy link
Member Author

ldez commented Jun 4, 2023

@pohly maybe this PR can interest you 😉

@ldez ldez force-pushed the feat/clean-custom-plugin branch 3 times, most recently from bb3aab6 to bd36265 Compare June 4, 2023 22:52
pkg/lint/lintersdb/custom_linters.go Outdated Show resolved Hide resolved
pkg/config/linters_settings.go Show resolved Hide resolved
@ldez ldez force-pushed the feat/clean-custom-plugin branch 2 times, most recently from 9e5c2c9 to 2b966e1 Compare June 6, 2023 21:59
@ldez ldez marked this pull request as ready for review June 6, 2023 22:00
@ldez ldez force-pushed the feat/clean-custom-plugin branch 2 times, most recently from 7665163 to a3496e3 Compare June 6, 2023 22:44
@ldez ldez requested a review from bombsimon June 9, 2023 15:33
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.

LGTM!

pkg/lint/lintersdb/custom_linters.go Outdated Show resolved Hide resolved
pkg/lint/lintersdb/custom_linters.go Show resolved Hide resolved
@ldez ldez force-pushed the feat/clean-custom-plugin branch from f6822d3 to 21f6cbd Compare June 10, 2023 15:41
pohly added a commit to pohly/logtools that referenced this pull request Jun 12, 2023
This implements the new interface from
golangci/golangci-lint#3887 with two fields in the
"settings":

type settings struct {
      Check  map[string]bool `json:"check"`
      Config string          `json:"config"`
}

This is the actual config *data*, not the name of a config file. This is
intentional because
- relative file paths wouldn't work (plugin cannot resolve them)
- loading additional file content wouldn't invalidate cached linter
  results the that embedding the data inside the main config does

The `include` text template method ensures that logcheck.conf gets injected
automatically. Having it as separate file has the advantage that manual
invocations of the stand-alone logcheck linter still work.
@pohly
Copy link
Contributor

pohly commented Jun 12, 2023

I've tested the current branch (= 21f6cbd) with kubernetes-sigs/logtools#18 successfully.

@ldez ldez force-pushed the feat/clean-custom-plugin branch from cc4906e to 3bb0ccb Compare June 13, 2023 21:47
@ldez ldez merged commit 25c2b07 into golangci:master Jun 15, 2023
16 checks passed
@ldez ldez deleted the feat/clean-custom-plugin branch June 15, 2023 12:39
linxiulei added a commit to linxiulei/logtools that referenced this pull request Jul 30, 2023
The new plugin interface was added in golangci/golangci-lint#3887
to allow settings for custom plugins. This commit implements the new
plugin interface with find `config` value in the settings, and passes it
to flag `--config`.
linxiulei added a commit to linxiulei/logtools that referenced this pull request Jul 30, 2023
The new plugin interface was added in golangci/golangci-lint#3887
to allow settings for custom plugins. This commit implements the new
plugin interface with find `config` value in the settings, and passes it
to flag `--config`.
linxiulei added a commit to linxiulei/logtools that referenced this pull request Jul 30, 2023
The new plugin interface was added in golangci/golangci-lint#3887
to allow settings for custom plugins. This commit implements the new
plugin interface with `config` value in the settings, and passes it
to flag `--config`.
@ldez ldez added this to the v1.54 milestone Mar 6, 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 linter: custom About custom/private linters
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make private linters support parameters
4 participants