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

Enhance goimports linter to support opinionated go import statements #3362

Closed
sebastien-rosset opened this issue Nov 15, 2022 · 1 comment
Closed
Labels
declined enhancement New feature or improvement

Comments

@sebastien-rosset
Copy link
Contributor

sebastien-rosset commented Nov 15, 2022

Your feature request related to a problem? Please describe.

This is a proposal to enhance the goimports linter to provide opinionated go import formatting rules. The linter could:

  1. Validate that go import statements are formatted according to the rules listed in x/tools/cmd/goimports: support repairing import grouping/ordering golang/go#20818.
  2. In autofix mode, reformat the go import statements according to the opinionated rules.

Issue 20818 is still in ideation stage, but there is already a concrete implementation: https://github.com/rinchsan/gosimports is effectively a drop-in replacement for the goimport command, with additional opinionated rules to group/order go import statements.

Describe the solution you'd like.

I can see two ways to implement this proposal:

  1. Introduce a new gosimport linter that uses gosimport instead of goimport.
  2. Add a new config attribute to the existing goimports linter. The setting would be used to control which command to use, e.g. goimport or gosimport.

Option 2 seems to be better for users of the golangci-lint tool. There would be one linter to control go import formatting rules, one place to document what the formatting rules are. Also, it seems fairly straightforward to modify https://github.com/golangci/gofmt/tree/master/goimports to support either gosimport or goimport.

Describe alternatives you've considered.

This is a new feature. I'm not aware of the ability to control which go import formatting tool can be used.

Additional context.

Assuming the -local argument is the same for goimport and gosimport:

  1. The gosimport command may reformat code that was previously formatted with goimport.
  2. The goimport command does not reformat code that was previously formatted with gosimport.
@sebastien-rosset sebastien-rosset added the enhancement New feature or improvement label Nov 15, 2022
@ldez
Copy link
Member

ldez commented Nov 15, 2022

gci already provide this.

@ldez ldez closed this as completed Nov 15, 2022
@ldez ldez added the declined label Nov 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
declined enhancement New feature or improvement
Projects
None yet
Development

No branches or pull requests

2 participants