diff --git a/pyproject.toml b/pyproject.toml index 6045df8..fc6608a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -108,3 +108,9 @@ packages = ["src/secfoo"] [tool.pytest.ini_options] testpaths = ["tests"] + +[tool.ruff.lint.flake8-bugbear] +# typer.Option and FastAPI's Form are designed to be used as parameter +# defaults (they describe the parameter, they aren't shared mutable state), +# so B008 reports them as false positives. +extend-immutable-calls = ["typer.Option", "fastapi.Form"] diff --git a/tests/test_lint_config.py b/tests/test_lint_config.py new file mode 100644 index 0000000..1b57609 --- /dev/null +++ b/tests/test_lint_config.py @@ -0,0 +1,32 @@ +"""ruff config: typer.Option / FastAPI Form defaults are not B008 findings.""" +from __future__ import annotations + +import importlib.util +import shutil +import subprocess +import sys +from pathlib import Path + +import pytest + +REPO_ROOT = Path(__file__).resolve().parent.parent + + +def _ruff() -> list[str]: + exe = shutil.which("ruff") + if exe: + return [exe] + if importlib.util.find_spec("ruff") is None: + pytest.skip("ruff is not installed (pip install -e '.[dev]')") + return [sys.executable, "-m", "ruff"] + + +def test_typer_and_fastapi_defaults_are_not_flagged_by_b008(): + result = subprocess.run( + [*_ruff(), "check", "src", "--select", "B008", "--output-format", "concise"], + check=False, + cwd=REPO_ROOT, + capture_output=True, + text=True, + ) + assert result.returncode == 0, result.stdout + result.stderr