Add ruff to the "lint" session
`ruff` runs alongside `flake8` and `isort`, with the rules aligned to theirs: - `noqa` comments go where both tools expect them - `import`s stay sorted case-insensitively, now stated explicitly in both tools - `print()` in the "docs" session became `session.log()`
This commit is contained in:
parent
175d722071
commit
318dff8fc8
1 changed files with 166 additions and 12 deletions
125
pyproject.toml
125
pyproject.toml
|
|
@ -108,6 +108,7 @@ dev = [
|
|||
"mypy (>=2.4.1,<3.0.0)",
|
||||
"pep8-naming (>=0.15.1,<0.16.0)",
|
||||
"pydoclint[flake8] (>=0.12.0,<0.13.0)",
|
||||
"ruff (>=0.17.6,<0.18.0)",
|
||||
]
|
||||
|
||||
test = [
|
||||
|
|
@ -315,7 +316,7 @@ pytest-parametrize-values-type = "list"
|
|||
# Source: https://pycqa.github.io/isort/docs/configuration/options.html
|
||||
|
||||
atomic = true
|
||||
case_sensitive = true
|
||||
case_sensitive = false # Implied by "force_alphabetical_sort_within_sections"
|
||||
combine_star = true
|
||||
force_alphabetical_sort_within_sections = true
|
||||
lines_after_imports = 2
|
||||
|
|
@ -418,6 +419,128 @@ markers = [
|
|||
|
||||
|
||||
|
||||
[tool.ruff]
|
||||
# Source: https://docs.astral.sh/ruff/
|
||||
|
||||
cache-dir = ".cache/ruff"
|
||||
|
||||
src = ["src"]
|
||||
|
||||
target-version = "py313"
|
||||
|
||||
line-length = 88
|
||||
|
||||
|
||||
[tool.ruff.format]
|
||||
|
||||
# Align with black
|
||||
quote-style = "double"
|
||||
skip-magic-trailing-comma = false
|
||||
|
||||
|
||||
[tool.ruff.lint] # aligned with [tool.flake8] above
|
||||
|
||||
select = [
|
||||
# ===================================
|
||||
# Violations also covered by `flake8`
|
||||
# ===================================
|
||||
# flake8-annotations => enforce type checking for functions
|
||||
"ANN0", "ANN2",
|
||||
# flake8-unused-arguments ("U100") => declared function arguments must be used
|
||||
"ARG",
|
||||
# flake8-bugbear => opinionated bugs and design flaws
|
||||
"B",
|
||||
# flake8-comprehensions => better comprehensions
|
||||
"C4",
|
||||
# mccabe => cyclomatic complexity
|
||||
"C90",
|
||||
# flake8-commas ("C8") => better comma placements
|
||||
"COM",
|
||||
# flake8-docstrings => PEP257 compliance
|
||||
"D",
|
||||
# pycodestyle => PEP8 compliance
|
||||
"E", "W",
|
||||
# pyflakes => basic errors
|
||||
"F",
|
||||
# pep8-naming => PEP8 naming conventions
|
||||
"N",
|
||||
# flake8-pytest-style => enforce a consistent style with pytest
|
||||
"PT",
|
||||
# flake8-quotes => use double quotes everywhere
|
||||
"Q",
|
||||
# flake8-bandit => common security issues
|
||||
"S",
|
||||
# flake8-debugger => no debugger usage
|
||||
"T10",
|
||||
# flake8-todos => unify TODOs
|
||||
"TD",
|
||||
# =======================================
|
||||
# Violations not covered by `flake8` above
|
||||
# =======================================
|
||||
# isort => imports are sorted
|
||||
"I",
|
||||
# flake8-print => no `print()`
|
||||
"T20",
|
||||
]
|
||||
|
||||
extend-ignore = [
|
||||
# Let the formatter handle trailing commas.
|
||||
"COM812",
|
||||
# Let's not do `@pytest.mark.no_cover()` instead of `@pytest.mark.no_cover`.
|
||||
"PT023",
|
||||
# TODOs need neither an author nor an issue.
|
||||
"TD002", "TD003",
|
||||
]
|
||||
|
||||
|
||||
[tool.ruff.lint.per-file-ignores]
|
||||
|
||||
# Top-levels of a sub-packages are intended to import a lot.
|
||||
"**/__init__.py" = ["F401"]
|
||||
# Type annotations are not strictly enforced.
|
||||
"migrations/env.py" = ["ANN0", "ANN2"]
|
||||
# - ANN0, ANN2 => Type annotations are not strictly enforced.
|
||||
# - S608 => Do not worry about SQL injection here.
|
||||
"migrations/versions/*.py" = ["ANN0", "ANN2", "S608"]
|
||||
# Type annotations are not strictly enforced.
|
||||
"noxfile.py" = ["ANN0", "ANN2"]
|
||||
# `print()` is ok in ad-hoc scripts
|
||||
"scripts/**" = ["T20"]
|
||||
# - ANN0, ANN2 => Type annotations are not strictly enforced.
|
||||
# - D106 => The `Meta` class inside the factory_boy models do not need a docstring.
|
||||
# - S101 => `assert` statements are ok in the test suite.
|
||||
# - S311 => The `random` module is not used for cryptography.
|
||||
"tests/**/*.py" = ["ANN0", "ANN2", "D106", "S101", "S311"]
|
||||
|
||||
|
||||
[tool.ruff.lint.flake8-pytest-style] # aligned with [tool.flake8] above
|
||||
|
||||
fixture-parentheses = false
|
||||
parametrize-names-type = "list"
|
||||
parametrize-values-row-type = "tuple"
|
||||
parametrize-values-type = "list"
|
||||
|
||||
|
||||
[tool.ruff.lint.isort] # aligned with [tool.isort] above
|
||||
|
||||
case-sensitive = false # Same as `isort`
|
||||
force-single-line = true
|
||||
lines-after-imports = 2
|
||||
order-by-type = false
|
||||
single-line-exclusions = ["typing"]
|
||||
|
||||
|
||||
[tool.ruff.lint.mccabe]
|
||||
|
||||
max-complexity = 10
|
||||
|
||||
|
||||
[tool.ruff.lint.pydocstyle]
|
||||
|
||||
convention = "google"
|
||||
|
||||
|
||||
|
||||
[tool.uv]
|
||||
# Source: https://docs.astral.sh/uv/reference/settings/
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue