Skip to content

Commit

Permalink
Refactor to avoid matchers
Browse files Browse the repository at this point in the history
  • Loading branch information
drdavella committed Feb 13, 2024
1 parent d510ee8 commit 453aa9c
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions src/codemodder/codemods/check_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import Mapping

import libcst as cst
from libcst import CSTVisitor, matchers
from libcst import CSTVisitor
from libcst.metadata import ParentNodeProvider
from libcst.metadata.base_provider import ProviderT # noqa: F401
from libcst._nodes.base import CSTNode # noqa: F401
Expand Down Expand Up @@ -52,22 +52,16 @@ def _process_simple_statement_line(self, stmt: cst.SimpleStatementLine) -> bool:
return True

# has a comment right above it
if matchers.matches(
stmt,
matchers.SimpleStatementLine(
match stmt:
case cst.SimpleStatementLine(
leading_lines=[
matchers.ZeroOrMore(),
matchers.EmptyLine(comment=matchers.Comment()),
*_,
cst.EmptyLine(comment=cst.Comment(value=comment_string)),
]
),
):
comment_string = stmt.leading_lines[-1].comment.value
if self._noqa_message_match(comment_string):
return True
if comment_string and self._is_pylint_disable_next_unused_imports(
comment_string
):
return True
return self._noqa_message_match(comment_string) or (
self._is_pylint_disable_next_unused_imports(comment_string)
)

return False

Expand Down

0 comments on commit 453aa9c

Please sign in to comment.