Skip to content

Go plugin system #841

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 16 commits into from
Jan 8, 2020
Merged

Go plugin system #841

merged 16 commits into from
Jan 8, 2020

Conversation

dbraley
Copy link
Contributor

@dbraley dbraley commented Nov 4, 2019

This PR attempts to address #473 & #839 by introducing the ability to use custom linter plugins.

I do not believe this adds significant rigidity to the project, as it leverages the existing LinterConfig struct to import custom linters from the config into the Manager, and then only when the .WithCustomLinters function is called. Because failure to load a custom linter doesn't stop the process, it was desirable to give the manager access to the logger as well.

The readme file currently references github.com/dbraley/example-linter for an example of how to create your own custom linter. Feel free to fork that or create another example if you'd rather not have the documentation point to an outside authors github. I completely understand if that's the case, and will gladly change the documentation to point to a different repo at your request.

@CLAassistant
Copy link

CLAassistant commented Nov 4, 2019

CLA assistant check
All committers have signed the CLA.

@dbraley
Copy link
Contributor Author

dbraley commented Nov 4, 2019

build seems to be failing for reasons unrelated to this PR

@ernado
Copy link
Member

ernado commented Nov 8, 2019

Hi, thank you for your PR and sorry for long response!
I will try to review it ASAP, but I'm currently overloaded on my job, so no ETA :(

Will link this PR to other maintainers and hopefully we will get some feedback.

Copy link
Contributor

@jirfag jirfag left a comment

Choose a reason for hiding this comment

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

great work, thank you!

}

type AnalyzerPlugin interface {
GetLinterName() string
Copy link
Contributor

Choose a reason for hiding this comment

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

name is already in the config, why duplicate it?
also, maybe we can move description to config to simplify things for linters authors?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, yeah, I can get onboard with that. Sounds good!

# Intended to point to the repo location of the linter. Optional, just for documentation purposes.
original-url: github.com/dbraley/example-linter
# Indicates if this linter should be considered slow. Optional, false by default.
slow: false
Copy link
Contributor

Choose a reason for hiding this comment

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

please, remove it for simplification. Linters with go/analysis interface can't be slow by current rules. The only slow linter is unused.

Copy link
Contributor Author

@dbraley dbraley Nov 11, 2019

Choose a reason for hiding this comment

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

I can remove it from the documentation with ease. Actually getting the code to ignore it could be slightly more problematic. But I think for what you're asking just removing the documentation of it should suffice, yes? edit: NM, was misremembering how this worked. That's easy to implement, will do.

path: /path/to/example.so
# If the linter should be enabled by default. Options in the `linters`
# section override this, including `disable-all`. Optional, false by default.
enabled: true
Copy link
Contributor

Choose a reason for hiding this comment

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

Why duplicate it with linters section? It looks difficult to understand for users.

Copy link
Contributor Author

@dbraley dbraley Nov 11, 2019

Choose a reason for hiding this comment

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

Hm. There are a couple of ways to reduce that duplication. The easiest and I think most consistent is to set the linter to enabled by default and remove this option. That does leave the 'problem' that if the user has linters:disable-all: true in the linters section, that will override enable by default even for the custom linters. Thus, the user will be forced to define the linter again in linters:enable. But that also preserves the ability to turn on and off custom linters on the command line.

README.md Outdated
In order to use plugins, you'll need a golangci-lint executable that can run them. The normal version of this project
is built with the vendors option, which breaks plugins that have overlapping dependencies.

1. Download the `i473` branch of https://github.com/dbraley/golangci-lint/tree/i473
Copy link
Contributor

Choose a reason for hiding this comment

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

We're going to merge it. Let's fix description.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, sorry, wanted the documentation to be accurate during the review. Will fix now.

README.md Outdated

### Configure Your Project for Linting
If you already have a linter plugin available, you can follow these steps to define it's usage in a projects
`.golangci.yml` file. An example linter can be found at https://github.com/dbraley/example-linter. If you're looking for
Copy link
Contributor

Choose a reason for hiding this comment

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

please point to github.com/golangci/example-plugin-linter. I will fork your repo into it.

@dbraley
Copy link
Contributor Author

dbraley commented Nov 25, 2019

@jirfag Just checking in, haven't seen any motion on this for a bit. Is there anything else that needs to be done to keep this moving forward?

@tpounds tpounds added the enhancement New feature or improvement label Dec 30, 2019
@jirfag jirfag merged commit be3c688 into golangci:master Jan 8, 2020
@jirfag
Copy link
Contributor

jirfag commented Jan 8, 2020

Sorry for the delay, merged it

@ldez ldez changed the title I473 Go plugin system Mar 1, 2024
@ldez ldez added the linter: custom About custom/private linters label Mar 1, 2024
@ldez ldez added this to the v1.23 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.

7 participants