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

Support unused import removal with Buildifier #379

Closed
psimmons-vistar opened this issue Sep 27, 2018 · 7 comments
Closed

Support unused import removal with Buildifier #379

psimmons-vistar opened this issue Sep 27, 2018 · 7 comments

Comments

@psimmons-vistar
Copy link

psimmons-vistar commented Sep 27, 2018

It would be nice if Buildifier could support detecting and removing unused load statement imports.

Would definitely be willing to work on this if I could be given some guidance on if this makes conceptual sense in Buildifier, and where in the code a modification like this would happen.

@laurentlb
Copy link
Contributor

Agree. This is blocked on this Bazel change: bazelbuild/bazel#5636
After that, it will be safe to remove those.

@kastiglione
Copy link

kastiglione commented Sep 27, 2018

According to https://github.com/bazelbuild/buildtools/blob/master/buildozer/README.md, buildozer has a fix unusedLoads command.

@psimmons-vistar
Copy link
Author

Sweet, I was wondering if it would've made more sense in buildozer. Thanks

@mboes
Copy link

mboes commented Jul 20, 2019

But AFAIK, buildozer only works on BUILD files, not Starlark files, right? How do I detect and remove unused imports in Starlark files?

@vladmos
Copy link
Member

vladmos commented Jul 20, 2019

You can use buildifier:

$ buildifier --lint=fix --warnings=load your/file.bzl

@thundergolfer
Copy link

thundergolfer commented Apr 17, 2020

@vladmos That command didn't do anything for me (version 0.29.0). This works though:

buildozer 'fix unusedLoads' //...:* (at least on BUILD files)

@vladmos
Copy link
Member

vladmos commented Apr 17, 2020

That's weird, could you please share a file that's not being fixed with buildifier?

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

No branches or pull requests

6 participants