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

chore: Fix linter findings for revive:exported in plugins/inputs/[a-b]* #15913

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

zak-pawel
Copy link
Collaborator

Summary

Address findings for revive:exported in plugins/inputs/[a-b]*.

As part of this effort for files from plugins/inputs/[a-b]*, the following actions were taken:

  • Type names (const, var, struct, func, etc) were changed to unexported, wherever they didn't need to be exported.
  • All remaining exported types were given comments in the appropriate form – this does not apply to exported methods that implement "known" plugin interfaces (Gather|Init|Start|Stop|SampleConfig|Parse|Add|Apply|Serialize|SerializeBatch|SetParser).
  • The order of methods was organized (exported methods first, then unexported, with init at the very end).

It is only part of the bigger job (for issue: #15813).
After all findings of this type in whole project are handled, we can enable revive:exported rule in golangci-lint.

Checklist

  • No AI generated code was used in this PR

Copy link
Member

@srebhan srebhan left a comment

Choose a reason for hiding this comment

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

Thanks for your effort @zak-pawel! I do have some comments with the most sever being to remove the useless comments! :-)

@@ -22,6 +22,7 @@ import (
//go:embed sample.conf
var sampleConfig string

// ActiveMQ Input Plugin
Copy link
Member

Choose a reason for hiding this comment

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

Please don't add these nonsense comments!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

OK :(

@@ -21,6 +21,7 @@ import (
//go:embed sample.conf
var sampleConfig string

// Aerospike Input Plugin
Copy link
Member

Choose a reason for hiding this comment

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

Same here (and potentially everywhere else ;-)) What information does this comment add?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed

Comment on lines 65 to 75
type externalAuth struct{}

// Mechanism returns "EXTERNAL"
func (a *externalAuth) Mechanism() string {
return "EXTERNAL"
}

// Response returns "\000"
func (a *externalAuth) Response() string {
return "\000"
}
Copy link
Member

Choose a reason for hiding this comment

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

Please revert this! Keep the struct close to the method definition of that struct and remove those comments telling you exactly the same as the code does!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed

@@ -207,7 +208,7 @@ func (a *Aurora) gatherScheduler(
return fmt.Errorf("%v", resp.Status)
}

var vars Vars
var vars vars
Copy link
Member

Choose a reason for hiding this comment

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

Ouch... This really hurts my eyes. :-)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think it's beautiful ;)

@zak-pawel
Copy link
Collaborator Author

I do have some comments with the most sever being to remove the useless comments! :-)

@srebhan
The thing is, the exported rule is designed to detect uncommented "things" of the exported type. And while we can filter out methods with known names, it will be hard for us to do that for several hundred plugins and their public structs.

The options I see are:

  1. Grit our teeth and put a comment like // StructureName over every public structure (representing a certain plugin) everywhere (we don't need anything more).
  2. As above, but put //nolint xD
  3. Did you know that these structs don't have to be exported? We can make them unexported... Only their fields need to be exported.
  4. We can take the same steps I took in this PR for the entire codebase (except for the structs we're talking about), but not enable the exported rule.

Point 2 seems very poor.
Similarly, point 4 - because I see value in this rule - it will make it easier for us to review new code, in which we often overlook that there are types that could be unexported.

@srebhan
Copy link
Member

srebhan commented Sep 30, 2024

@zak-pawel how about adding a config option to the linter? :-)

@zak-pawel
Copy link
Collaborator Author

zak-pawel commented Sep 30, 2024

@zak-pawel how about adding a config option to the linter? :-)

@srebhan To disable checking whether comments exist on the exported structs?

@srebhan
Copy link
Member

srebhan commented Sep 30, 2024

Yes. We just need a PR on revive for that. :-P

@zak-pawel
Copy link
Collaborator Author

Yes. We just need a PR on revive for that. :-P

@srebhan Such PR already exists: mgechev/revive#1047

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants