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

Consistent imports aliases check #1413

Closed
nikolaydubina opened this issue Jun 8, 2023 · 1 comment
Closed

Consistent imports aliases check #1413

nikolaydubina opened this issue Jun 8, 2023 · 1 comment

Comments

@nikolaydubina
Copy link

I would like to propose check that import aliases (renamed imports) are the same within same repository.

It works fairly well for large codebases.

There are false negatives though, due to limitation of go analysis toolchain to provide list of packages in single analysis run.

However, there is no false positives. And it is fairly useful.

I saw issues in kubernetes and many other large codebases.

Cheers ! 🐱

https://github.com/nikolaydubina/consistentimports

@nikolaydubina nikolaydubina added the needs-triage Newly filed issue that needs triage label Jun 8, 2023
@dominikh
Copy link
Owner

dominikh commented Jun 8, 2023

I'm afraid I don't think this belongs in Staticcheck. In my mind, the primary reason for renaming imports is to avoid conflicts — either with other imports, or with commonly used variable names. As such, what needs to be renamed, and what alias is the best fit, can vary on a file by file basis.

Imagine a package that already renames an import in various places and where the same import has to be renamed in a new file. But in the new file, the currently used alias would conflict with yet something else. It would be undesirable to have to stick with the alias just because it's common, and it would be even more undesirable to have to change the alias in all existing files to a new common one.

Imports in Go are file-local, and I think that justifies allowing file-local decisions as to the aliases used.

P.S. I see that your repository's readme lists this issue as "integration to linter aggregators". I'd like to point out that this isn't an aggregator, but a self-contained and cohesive set of checks, and we don't import the checks of other tools.

@dominikh dominikh closed this as not planned Won't fix, can't repro, duplicate, stale Jun 8, 2023
@dominikh dominikh added new-check and removed needs-triage Newly filed issue that needs triage labels Jun 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants