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.

Comment From: gabyhelp

Related Issues

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

Comment From: adonovan

@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.

Comment From: adonovan

cc: @synenka