-
Notifications
You must be signed in to change notification settings - Fork 189
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
Add codemod command for removing unused imports #266
Conversation
Codecov Report
@@ Coverage Diff @@
## master #266 +/- ##
==========================================
- Coverage 93.89% 93.89% -0.01%
==========================================
Files 214 216 +2
Lines 20822 20854 +32
==========================================
+ Hits 19550 19580 +30
- Misses 1272 1274 +2
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good!
Can you add test cases in this directory like the other codemods?
https://github.com/Instagram/LibCST/tree/master/libcst/codemod/commands/tests
Done! Thanks for the review. I'm wondering if we could have some better documentation about what these built-in codemods do. |
@zsol , your change has a lint error which the updated imports are not sorted. You can |
No I meant for the Linters fixed, sorry :) |
import a | ||
x: a = 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw, RemoveImportsVisitor uses scope analysis and it doesn't analyze string type annotation.
That means, in this example code, import a
will be removed by this codemod.
import a
x: "a" = 1
In general, RemoveUnusedImportsCommand
should be used with cautions since it has limitations including it doesn't consider imports used by other modules (indirect imports) and it doesn't consider references in string type annotations.
@zsol, would you like to include those as warnings as document? Probably short description in DESCRIPTION
attr and longer explanation in docstring of RemoveUnusedImportsCommand
.
We have a codemod tutorial presents usage of libcst CLI. |
I was suggesting to generate an actual list of available codemods (along with their docs) in either the tutorial there, or the reference manual part. This would allow people to explore them without needing to install |
That's great idea and can make it more clear about available commands. One way to do it is to generate codemod command list reStructuredText in |
Seems like imports that are used in f-strings are not tracked either, guess it's similar to the string type annotation issue! |
Test Plan
Ran on an earlier version of this file: