Skip to content

runAnalyzersConfig: export analyzers #2710

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

Closed
wants to merge 1 commit into from

Conversation

sluongng
Copy link

@sluongng sluongng commented Apr 1, 2022

Overview

In order to use golangci-lint in non-trivial use cases, such as Bazel's rules_go's 'nogo' static analysis framework, we would need to make the analysis.Analyzer defined for various different golinters be reuseable outside of golangci-lint.

Export the GetAnalyzers function of runAnalyzersConfig interface as well as adjusting the 2 implementations of that interface: goanalysis.Linter and goanalysis.MetaLinter

This should help enable other packages to be able to consumer golangci-lint analyzers for different use cases.

Technical details

Once this is merged, we can build a solution for issue #1473 by generating a new Go package for each linter in golangci-lint. With each package contains only one file like this:

// Generated code. DO NOT MODIFY.
package nogoGofumpt

import (
	"github.com/golangci/golangci-lint/pkg/golinters"
)

// Assuming that there is only 1 analyzer for each linter
var Analyzer = golinters.NewGofumpt().GetAnalyzers()[0]

Bazel rules_go's nogo static analysis then would be able to consume this package as the documentation stated here https://github.com/bazelbuild/rules_go/blob/master/go/nogo.rst#id8

In order to use golangci-lint in non-trivial use cases, such as Bazel's
rules_go's 'nogo' static analysis framework, we would need to make the
analysis.Analyzer defined for various different golinters be reuseable
outside of golangci-lint.

Export the GetAnalyzers function of runAnalyzersConfig interface as well
as adjusting the 2 implementations of that interface: goanalysis.Linter
and goanalysis.MetaLinter

This should help enable other packages to be able to consumer
golangci-lint analyzers for different use cases.
@boring-cyborg
Copy link

boring-cyborg bot commented Apr 1, 2022

Hey, thank you for opening your first Pull Request !

@CLAassistant
Copy link

CLAassistant commented Apr 1, 2022

CLA assistant check
All committers have signed the CLA.

@ldez ldez self-requested a review April 1, 2022 09:23
@ldez ldez added the blocked Need's direct action from maintainer label Apr 1, 2022
@sluongng
Copy link
Author

sluongng commented Apr 6, 2022

@ldez is there anything I could do to help unblocking this?

@sluongng
Copy link
Author

I discussed with @Helcaraxan updated the PR description with a bit more technical details.

Copy link

@telus-dvanamst telus-dvanamst left a comment

Choose a reason for hiding this comment

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

Admittedly I have not contributed to golangci-lint in recent times, however @sluongng attracted my attention to this PR as he needs to get it merged to support the work on #1473.

Based on the conversation in that issue, the minor size of this change and the amount of developer value that would be unlocked by it I feel that it's better here to merge and "ask for forgiveness, rather than permission".

@ldez ldez self-assigned this Apr 11, 2022
@martinbaillie
Copy link

Just chiming in as a user to say I'm very keen to see this Bazel nogo enabling work land and happy to help with testing.

@paiyar
Copy link

paiyar commented Jan 24, 2024

@ldez @Helcaraxan @alexandear Could you please revisit this? There is a lot of interest from the community of Golang & Bazel users and we'd direly like to leverage Golangci-lint in a native way as this paves the way for.

@alexandear

This comment was marked as off-topic.

alexandear
alexandear previously approved these changes Jan 24, 2024
@ldez ldez dismissed alexandear’s stale review January 24, 2024 20:11

The status of this PR is Blocked.

@sluongng
Copy link
Author

Let's just close this stale PR.

Since this PR was opened, I have taken alternative routes to export analyzers from golangci-lint: see nogo-analyzer/golangci-lint and nogo-analyzer/goci-lint.

My understanding of golangci-lint is very out of date since I last looked at this, but I think it's hard to make a systematic export of analyzers from golangci-lint as they are tightly coupled with the configurations framework inside the runner binary. What you gonna get is a set of very slow analyzers as each one of them would need to initialize the configuration of golangci-lint runner.

Instead, in goci-lint, I took the source of these analyzers such as github.com/golangci/gofmt/gofmt or github.com/gordonklaus/ineffassign/pkg/ineffassign and make new, light weighted, standalone analyzer struct out of them. This requires a bit more manual wiring, but they are a lot faster to run in massive monorepo

@sluongng sluongng closed this Jan 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked Need's direct action from maintainer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants