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(linters): Enforce import hrouping with gci linter #16526

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

Conversation

paulojmdias
Copy link
Contributor

@paulojmdias paulojmdias commented Feb 18, 2025

Summary

This PR updates golangci-lint to enforce proper import grouping using the gci linter. The import sections are now structured as follows:

  • Standard → Go built-in packages (e.g., fmt, time).
  • Default → Third-party dependencies (e.g., github.com/likexian/whois).
  • Local → github.com/influxdata/telegraf modules.

The following command to fix all the modules with this linter can be executed like below. I will wait for the repo maintainers feedback to run this linter command to fix all the code needed in the repo.

gci write -s standard -s default -s localmodule .

Checklist

  • No AI generated code was used in this PR

Related issues

The discussion comes from the following PR comment: #16509 (comment)

@Hipska
Copy link
Contributor

Hipska commented Feb 19, 2025

Usually the PR to enable a linter also includes fixes to all the files not compliant, so the CI succeeds. If there are too many changes to be done, they are put in different preceding PRs, but I don't this is needed in this case as it should normally only be a small change in the top section of the file.

Examples

@zak-pawel
Copy link
Collaborator

@paulojmdias
As @Hipska mentioned, we either enable a new linter while fixing all its findings in a single PR or, if there are many findings, we first fix everything across multiple PRs and then enable the linter at the end.

@paulojmdias
Copy link
Contributor Author

@zak-pawel @Hipska I pushed the changes needed either way.

Please review and let me know if it is really needed to split it into multiple PRs.

Copy link
Collaborator

@zak-pawel zak-pawel left a comment

Choose a reason for hiding this comment

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

Looks good! Thanks!

Copy link
Contributor

@Hipska Hipska left a comment

Choose a reason for hiding this comment

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

Great addition which will keep all the code consistent!

@telegraf-tiger
Copy link
Contributor

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 the epic work @paulojmdias!

@srebhan srebhan added ready for final review This pull request has been reviewed and/or tested by multiple users and is ready for a final review. linter labels Feb 20, 2025
@srebhan srebhan changed the title chore(linters): Enforce Proper Import Grouping Using gci in golangci-lint chore(linters): Enforce import hrouping with gci linter Feb 20, 2025
@paulojmdias
Copy link
Contributor Author

Thanks for the epic work @paulojmdias!

You're welcome 💪

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.

5 participants