golangci / golangci-lint

Fast linters runner for Go
https://golangci-lint.run
GNU General Public License v3.0
15.39k stars 1.37k forks source link

more flexible loading of custom plugins #3826

Open pohly opened 1 year ago

pohly commented 1 year ago

Your feature request related to a problem? Please describe.

In Kubernetes, we have a hack/golangci-lint.yaml with a path for a logcheck.so which is relative to that config: https://github.com/kubernetes/kubernetes/blob/b09b7e5bdb1c763c6d7e47e2c792d54f37f7d9a2/hack/golangci.yaml#L42

That works because normally, _output contains build artifacts. It fails when using containerized builds where build artifacts are located elsewhere: https://github.com/kubernetes/kubernetes/issues/117831

Describe the solution you'd like.

When loading a plugin, golangci-lint could first try the absolute or relative path and if that file doesn't exist, fall back to searching for the plugin in directories specified via env variables. This could be PATH (kind of convenient because the plugin gets compiled together with the golangci-lint binary to ensure that both use the same Go and compile options and already gets placed in the same directory) or a custom variable like GOLANGCI_LINT_CUSTOM_PLUGIN_PATH.

Describe alternatives you've considered.

Additional context.

No response

boring-cyborg[bot] commented 1 year ago

Hey, thank you for opening your first Issue ! 🙂 If you would like to contribute we have a guide for contributors.

ldez commented 1 year ago

Hello,

When loading a plugin, golangci-lint could first try the absolute or relative path and if that file doesn't exist, fall back to searching for the plugin in directories specified via env variables.

Do you mean: if the path is a relative path then use the env var as a root? ex: ./foo/foo.so => filepath.Join("GOLANGCI_LINT_CUSTOM_PLUGIN_PATH", "./foo/foo.so")

Side note: maybe logcheck can be "merged" with loggercheck

pohly commented 1 year ago

I would:

logcheck is heavily biased towards Kubernetes logging conventions. I don't think it can or should get merged with other linters, even if some aspects of it are similar.

pohly commented 11 months ago

I was pinged again about this because it's still unsolved for containerized Kubernetes builds.

Any preference on how to solve this? I'm leaning towards falling back to PATH when some relative path doesn't resolve to an actual file and could prepare a PR with that.