Skip to content

Commit f1c5647

Browse files
committed
Run ruff on the sanity tests, why not.
1 parent 311e03c commit f1c5647

File tree

4 files changed

+86
-14
lines changed

4 files changed

+86
-14
lines changed

.pre-commit-config.yaml

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,22 @@ repos:
1313
- id: mixed-line-ending
1414
args: [--fix, lf]
1515
- id: trailing-whitespace
16-
- repo: https://github.com/pre-commit/mirrors-prettier
17-
rev: "v4.0.0-alpha.8"
18-
hooks:
19-
- id: prettier
20-
exclude_types: ["markdown"]
21-
- repo: https://github.com/PyCQA/isort
22-
rev: 5.13.2
23-
hooks:
24-
- id: isort
25-
- repo: https://github.com/asottile/pyupgrade
26-
rev: v3.15.1
16+
- repo: https://github.com/astral-sh/ruff-pre-commit
17+
rev: "v0.2.2"
2718
hooks:
28-
- id: pyupgrade
19+
- id: ruff
20+
args: [--fix, --exit-non-zero-on-fix]
2921
- repo: https://github.com/psf/black
3022
rev: 24.2.0
3123
hooks:
3224
- name: black
3325
id: black
3426
args: ["--line-length", "79"]
27+
- repo: https://github.com/pre-commit/mirrors-prettier
28+
rev: "v4.0.0-alpha.8"
29+
hooks:
30+
- id: prettier
31+
exclude_types: ["markdown"]
3532
- repo: https://github.com/DavidAnson/markdownlint-cli2
3633
rev: v0.12.1
3734
hooks:

noxfile.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
nox.options.sessions = []
88

99

10-
def session(default=True, **kwargs):
10+
def session(default=True, **kwargs): # noqa: D103
1111
def _session(fn):
1212
if default:
1313
nox.options.sessions.append(kwargs.get("name", fn.__name__))
@@ -18,5 +18,17 @@ def _session(fn):
1818

1919
@session()
2020
def tests(session):
21+
"""
22+
Run the sanity test suite to check the tests themselves.
23+
"""
2124
session.install("jsonschema", "pytest")
2225
session.run("pytest", *session.posargs)
26+
27+
28+
@session(tags=["style"])
29+
def style(session):
30+
"""
31+
Check Python code style in the sanity test suite.
32+
"""
33+
session.install("ruff")
34+
session.run("ruff", "check", ROOT, __file__)

pyproject.toml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,66 @@ combine_as_imports = true
33
from_first = true
44
include_trailing_comma = true
55
multi_line_output = 3
6+
7+
[tool.ruff]
8+
line-length = 79
9+
10+
[tool.ruff.lint]
11+
select = ["ALL"]
12+
ignore = [
13+
"A001", # It's fine to shadow builtins
14+
"A002",
15+
"A003",
16+
"ARG", # This is all wrong whenever an interface is involved
17+
"ANN", # Just let the type checker do this
18+
"B006", # Mutable arguments require care but are OK if you don't abuse them
19+
"B008", # It's totally OK to call functions for default arguments.
20+
"B904", # raise SomeException(...) is fine.
21+
"B905", # No need for explicit strict, this is simply zip's default behavior
22+
"C408", # Calling dict is fine when it saves quoting the keys
23+
"C901", # Not really something to focus on
24+
"D105", # It's fine to not have docstrings for magic methods.
25+
"D107", # __init__ especially doesn't need a docstring
26+
"D200", # This rule makes diffs uglier when expanding docstrings
27+
"D203", # No blank lines before docstrings.
28+
"D212", # Start docstrings on the second line.
29+
"D400", # This rule misses sassy docstrings ending with ! or ?
30+
"D401", # This rule is too flaky.
31+
"D406", # Section headers should end with a colon not a newline
32+
"D407", # Underlines aren't needed
33+
"D412", # Plz spaces after section headers
34+
"EM101", # These don't bother me, it's fine there's some duplication.
35+
"EM102",
36+
"FBT", # It's worth avoiding boolean args but I don't care to enforce it
37+
"FIX", # Yes thanks, if I could it wouldn't be there
38+
"N", # These naming rules are silly
39+
"PLR0912", # These metrics are fine to be aware of but not to enforce
40+
"PLR0913",
41+
"PLR0915",
42+
"PLW2901", # Shadowing for loop variables is occasionally fine.
43+
"PT006", # pytest parametrize takes strings as well
44+
"PYI025", # wat, I'm not confused, thanks.
45+
"RET502", # Returning None implicitly is fine
46+
"RET503",
47+
"RET505", # These push you to use `if` instead of `elif`, but for no reason
48+
"RET506",
49+
"RSE102", # Ha, what, who even knew you could leave the parens off. But no.
50+
"SIM300", # Not sure what heuristic this uses, but it's easily incorrect
51+
"SLF001", # Private usage within this package itself is fine
52+
"TD", # These TODO style rules are also silly
53+
"UP007", # We support 3.8 + 3.9
54+
]
55+
56+
[tool.ruff.lint.flake8-pytest-style]
57+
mark-parentheses = false
58+
59+
[tool.ruff.lint.flake8-quotes]
60+
docstring-quotes = "double"
61+
62+
[tool.ruff.lint.isort]
63+
combine-as-imports = true
64+
from-first = true
65+
66+
[tool.ruff.lint.per-file-ignores]
67+
"noxfile.py" = ["ANN", "D100", "S101", "T201"]
68+
"test_*.py" = ["ANN", "D", "RUF012", "S", "PLR", "TRY"]

test_sanity.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def test_tests_are_valid(test_path):
2929
try:
3030
test = json.loads(test_path.read_text())
3131
except json.JSONDecodeError:
32-
assert False, f"{test_path} contains invalid JSON"
32+
pytest.fail(f"{test_path} contains invalid JSON")
3333
else:
3434
VALIDATOR.validate(test)
3535

0 commit comments

Comments
 (0)