Skip to content

Commit

Permalink
A bit of cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
drdavella committed Feb 13, 2024
1 parent 453aa9c commit b3cf5cb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/codemodder/codemods/check_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def _process_simple_statement_line(self, stmt: cst.SimpleStatementLine) -> bool:

def is_disabled_by_linter(self, node: cst.CSTNode) -> bool:
"""
Check if the import has a #noqa or # pylint: disable(-next)=unused_imports comment attached to it.
Check if the import has a #noqa or # pylint: disable(-next) comment attached to it.
"""
match self.get_metadata(ParentNodeProvider, node):
case cst.SimpleStatementLine() as stmt:
Expand Down Expand Up @@ -120,7 +120,7 @@ def is_disabled_by_annotations(
messages: list[str],
) -> bool:
"""
Check if the import has a #noqa or # pylint: disable(-next)=unused_imports comment attached to it.
Check if the import has a #noqa or # pylint: disable(-next) comment attached to it.
"""
visitor = _GatherCommentNodes(metadata, messages)
node.visit(visitor)
Expand Down
6 changes: 5 additions & 1 deletion src/core_codemods/remove_unused_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class RemoveUnusedImports(SimpleCodemod):
ParentNodeProvider,
)

IGNORE_ANNOTATIONS = ["unused-import", "F401", "W0611"]

def transform_module_impl(self, tree: cst.Module) -> cst.Module:
# Do nothing in __init__.py files
if self.file_context.file_path.name == "__init__.py":
Expand All @@ -42,7 +44,9 @@ def transform_module_impl(self, tree: cst.Module) -> cst.Module:
pos = self.get_metadata(PositionProvider, import_alias)
if self.filter_by_path_includes_or_excludes(pos):
if not is_disabled_by_annotations(
importt, self.metadata, messages=["unused-import", "W0611", "F401"] # type: ignore
importt,
self.metadata, # type: ignore
messages=self.IGNORE_ANNOTATIONS,
):
self.file_context.codemod_changes.append(
Change(pos.start.line, self.change_description)
Expand Down
3 changes: 2 additions & 1 deletion src/core_codemods/subprocess_shell_false.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class SubprocessShellFalse(SimpleCodemod, NameResolutionMixin):
]

METADATA_DEPENDENCIES = SimpleCodemod.METADATA_DEPENDENCIES + (ParentNodeProvider,)
IGNORE_ANNOTATIONS = ["S603"]

def leave_Call(self, original_node: cst.Call, updated_node: cst.Call):
if not self.filter_by_path_includes_or_excludes(
Expand All @@ -52,7 +53,7 @@ def leave_Call(self, original_node: cst.Call, updated_node: cst.Call):
) and not is_disabled_by_annotations(
original_node,
self.metadata, # type: ignore
messages=["S603"],
messages=self.IGNORE_ANNOTATIONS,
):
self.report_change(original_node)
new_args = self.replace_args(
Expand Down

0 comments on commit b3cf5cb

Please sign in to comment.