Skip to content

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

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 5 commits into from
Oct 9, 2024

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! :-)

@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

@telegraf-tiger
Copy link
Contributor

telegraf-tiger bot commented Oct 4, 2024

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.

Nice, just one comment regarding the toml-option naming.

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 @zak-pawel!

@srebhan srebhan added the ready for final review This pull request has been reviewed and/or tested by multiple users and is ready for a final review. label Oct 9, 2024
@srebhan srebhan assigned mstrandboge and unassigned srebhan Oct 9, 2024
@mstrandboge mstrandboge merged commit f4f7a63 into influxdata:master Oct 9, 2024
26 of 27 checks passed
@github-actions github-actions bot added this to the v1.32.2 milestone Oct 9, 2024
asaharn pushed a commit to asaharn/telegraf that referenced this pull request Oct 16, 2024
srebhan pushed a commit that referenced this pull request Oct 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore linter ready for final review This pull request has been reviewed and/or tested by multiple users and is ready for a final review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants