-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
gci: Add trailing slash to local module #4608
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
Comments
Hello, I recommend opening an issue to the linter repo: https://github.com/daixiang0/gci golangci-lint is a wrapper around linter. |
Agreed that golangci-lint is a wrapper around linters. However, your hack #4522 (comment) is what I'm proposing to be modified: https://github.com/golangci/golangci-lint/pull/4522/files#diff-298e405f64d9b95decc7390b518fc1bd580eb8aee31a7eb7d7e83f5ca6527e6aR154-R169 |
In some way, my hack is just what the linter does, the problem is not my hack but how localModule is handled inside the linter. |
Then the hack should be removed, no? |
No, because the linter doesn't work inside golangci-lint without this hack. The problem is here: https://github.com/daixiang0/gci/blob/4f7ff3c79e25e9076af03eab88e658d7448ae7de/pkg/section/local_module.go#L21 |
The fix: if spec.Path == m.Path || strings.HasPrefix(spec.Path, m.Path+"/") { instead of: if strings.HasPrefix(spec.Path, m.Path) { |
Thanks for that, I was about to make a different PR: daixiang0/gci#203 |
I think your PR will create a side effect with a module without packages. My PR fixes the problem at the root without any side effects. |
Thanks. Your understanding is better than mine. I hope it can be merged to |
I added tests into the PR to illustrate the problem with your PR: daixiang0/gci@005b33c You can close your PR because it will create a regression. Note: |
Welcome
Description of the problem
In my company's package, there are a few repositories that are named similarly, because they are related, and one is imported in the other (for example, a separate proto repository).
e.g.:
Main program: github.com/Company/main-program
Dependency: github.com/Company/main-program-dependency
This unfortunately confuses
gci
when trying to use thelocalmodule
section, as imports from both repos get grouped as one.e.g:
When they should be separate, e.g:
Adding the local module as it's own custom section with the trailing slash gets around this (i.e.
prefix("github.com/Company/main-program/")
), but I would prefer to rely in the linter's detection so I can use the same config across multiple repos in our org.This could be done by modifying https://github.com/golangci/golangci-lint/blob/master/pkg/golinters/gci.go#L169 to be:
Version of golangci-lint
Configuration
Go environment
Verbose output of running
A minimal reproducible example or link to a public repository
An example, non-functioning, code sample.
Expected:
Validation
The text was updated successfully, but these errors were encountered: