Skip to content

Commit

Permalink
Add test for linting empty source
Browse files Browse the repository at this point in the history
  • Loading branch information
sco1 committed May 13, 2024
1 parent 3faf647 commit 30976ac
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 4 additions & 2 deletions flake8_annotations/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def __init__(self, tree: t.Optional[ast.Module], lines: t.List[str]):
# Type ignores are provided by ast at the module level & we'll need them later when deciding
# whether or not to emit errors for a given function
self._type_ignore_lineno = {ti.lineno for ti in self.tree.type_ignores}
self._has_mypy_ignore_errors = "# mypy: ignore-errors" in lines[0]
self._has_mypy_ignore_errors = "# mypy: ignore-errors" in lines[0] if lines else False

# Set by flake8's config parser
self.suppress_none_returning: bool
Expand Down Expand Up @@ -119,7 +119,9 @@ def run(self) -> t.Generator[FORMATTED_ERROR, None, None]:
if function.lineno in self._type_ignore_lineno:
# function-level ignore
continue
elif (1 in self._type_ignore_lineno) or (self._has_mypy_ignore_errors):
elif (1 in self._type_ignore_lineno) or (
self._has_mypy_ignore_errors
): # pragma: no branch
# module-level ignore
# lineno from ast is 1-indexed
continue
Expand Down
6 changes: 6 additions & 0 deletions testing/test_empty_src.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from testing.helpers import check_source


def test_empty_source() -> None:
errs = check_source("")
assert len(list(errs)) == 0

0 comments on commit 30976ac

Please sign in to comment.