Skip to content

Commit

Permalink
Add codemod command for removing unused imports
Browse files Browse the repository at this point in the history
  • Loading branch information
zsol committed Mar 17, 2020
1 parent f612604 commit 3666f7e
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions libcst/codemod/commands/remove_unused_imports.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
#
# pyre-strict

from libcst import Import, ImportFrom
from libcst.codemod import VisitorBasedCodemodCommand
from libcst.codemod.visitors import RemoveImportsVisitor


class RemoveUnusedImportsCommand(VisitorBasedCodemodCommand):
DESCRIPTION: str = "Remove all imports that are not used in a file."

def visit_Import(self, node: Import) -> bool:
RemoveImportsVisitor.remove_unused_import_by_node(self.context, node)
return False

def visit_ImportFrom(self, node: ImportFrom) -> bool:
RemoveImportsVisitor.remove_unused_import_by_node(self.context, node)
return False

0 comments on commit 3666f7e

Please sign in to comment.