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

vfmt: remove unused imports #21169

Closed
wants to merge 4 commits into from
Closed

Conversation

ttytm
Copy link
Member

@ttytm ttytm commented Apr 2, 2024

Resolves a TODO for vfmt adding/fixing removal of unused imports. It does so respecting user comments.

v/vlib/v/fmt/fmt.v

Lines 343 to 346 in a1b6360

if imp.mod !in f.used_imports {
// TODO: bring back once only unused imports are removed
// continue
}

I think vlib/v/fmt/tests/import_comments_expected.vv is the best file in the updated test showcasing the behavior.

Includes minor quality improvements. Next step would fixing/extending auto imports.

@spytheman
Copy link
Member

Automatically removing unused imports is very breaking for prototyping. Imho the warning that is currently present, is more than enough.

@spytheman spytheman closed this Apr 2, 2024
@spytheman
Copy link
Member

Autoimporting is imho also a bad idea, because it is a heuristic, that can not work reliably in all or even most cases, since vfmt works on single files, and thus has no idea, whether the os.abc that you wrote somewhere in a file, means that you want to import os or import myproject.os or import xyz as os.

@spytheman
Copy link
Member

I think, we should at some point, do a cleanup of such TODO: items, that may have seemed good on the surface initially, but that turned out to have big negatives revealed later.

@ttytm
Copy link
Member Author

ttytm commented Apr 2, 2024

Yes it is better to solve this via import completion of a ls. V-analyzer could support it.

@ttytm
Copy link
Member Author

ttytm commented Apr 2, 2024

@spytheman should we than remove the current auto imports?

@ttytm ttytm deleted the fmt/remove-unused branch April 14, 2024 06:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants