Skip to content

x/tools/go/analysis/internal/checker: -fix should remove unneeded imports #72035

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

Open
adonovan opened this issue Feb 28, 2025 · 2 comments
Open
Assignees
Labels
FixPending Issues that have a fix which has not yet been reviewed or submitted. ToolProposal Issues describing a requested change to a Go tool or command-line program. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@adonovan
Copy link
Member

The -fix flag of each {single,multi}checker tool applies as many fixes as possible without textual conflicts. However, semantic conflicts are still possible. The most common kind of semantic conflict is to leave unused imports in the file. Consider: if a file contains two fixes, each of which removes one use of an import, then each fix is safe to apply in isolation, but when applied together the import becomes unused.

This is sufficiently common that it is worth making the fixer's final step to check for unused imports and remove them, ideally without having to re-typecheck the file.

@gabyhelp
Copy link

Related Issues

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

@gabyhelp gabyhelp added the ToolProposal Issues describing a requested change to a Go tool or command-line program. label Feb 28, 2025
@seankhliao seankhliao changed the title go/analysis/internal/checker: -fix should remove unneeded imports xltools/go/analysis/internal/checker: -fix should remove unneeded imports Feb 28, 2025
@seankhliao seankhliao changed the title xltools/go/analysis/internal/checker: -fix should remove unneeded imports x/tools/go/analysis/internal/checker: -fix should remove unneeded imports Feb 28, 2025
@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Feb 28, 2025
@gopherbot gopherbot added this to the Unreleased milestone Feb 28, 2025
@adonovan
Copy link
Member Author

@jba: this issue is essentially identical to the problem you fixed recently in the inliner:
currently applyFixes in go/analysis/internal/checker/checker.go only formats the final file, but we need a final post-processing step to remove unused imports, without type checking. Your algorithm would do the trick.

@adonovan adonovan removed their assignment Apr 21, 2025
@JunyangShao JunyangShao added the FixPending Issues that have a fix which has not yet been reviewed or submitted. label Apr 22, 2025
@jba jba self-assigned this Apr 22, 2025
@adonovan adonovan marked this as a duplicate of #73578 May 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FixPending Issues that have a fix which has not yet been reviewed or submitted. ToolProposal Issues describing a requested change to a Go tool or command-line program. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

5 participants