Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion flake8_async/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,19 @@ def main() -> int:
]
any_error = False
for file in all_filenames:
plugin = Plugin.from_filename(file)
try:
plugin = Plugin.from_filename(file)
except SyntaxError as error:
location = file
if error.lineno is not None and error.offset is not None:
location = f"{file}:{error.lineno}:{error.offset}"
python_version = f"{sys.version_info.major}.{sys.version_info.minor}"
print(
f"{location}: SyntaxError (Python {python_version}): {error.msg}",
file=sys.stderr,
)
any_error = True
continue
for error in sorted(plugin.run()):
print(f"{file}:{error}")
any_error = True
Expand Down
42 changes: 42 additions & 0 deletions tests/test_config_and_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,48 @@ def test_run_flake8_async(tmp_path: Path):
assert res.stdout == EXAMPLE_PY_ERROR.encode("ascii")


def test_run_flake8_async_continues_after_syntax_error(tmp_path: Path):
invalid = tmp_path / "invalid.py"
invalid.write_text("if True\n pass\n")
write_examplepy(tmp_path)
res = subprocess.run(
["flake8-async", "--autofix=ASYNC", "./invalid.py", "./example.py"],
cwd=tmp_path,
capture_output=True,
check=False,
text=True,
)

python_version = f"{sys.version_info.major}.{sys.version_info.minor}"
assert res.returncode == 1
assert (
res.stderr
== f"./invalid.py:1:8: SyntaxError (Python {python_version}): expected ':'\n"
)
assert res.stdout == EXAMPLE_PY_ERROR
assert invalid.read_text() == "if True\n pass\n"
assert_autofixed(tmp_path)


def test_run_flake8_async_syntax_error_without_location(tmp_path: Path):
write_examplepy(tmp_path, text="# coding: nonexistent_codec\n")
res = subprocess.run(
["flake8-async", "./example.py"],
cwd=tmp_path,
capture_output=True,
check=False,
text=True,
)

python_version = f"{sys.version_info.major}.{sys.version_info.minor}"
assert res.returncode == 1
assert res.stderr.startswith(
f"./example.py: SyntaxError (Python {python_version}): "
)
assert res.stderr.endswith("nonexistent_codec\n")
assert not res.stdout


def test_systemexit_0(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
):
Expand Down
Loading