Build(ruff): Add complexity ratchet gate

Nothing stopped functions from growing back after the #816 splits.
Enable mccabe C901 and pylint PLR0912, PLR0913 and PLR0915 with each
limit set to the worst case measured in custom_components/ on the
merged tree, so the current code passes and any growth fails:

- C901 complexity: 16 (store_sync.py:208)
- PLR0912 branches: 15 (store_sync.py:208)
- PLR0913 arguments: 7 (checkin_protection.py, codegen.py,
  bookings_only.py)
- PLR0915 statements: 46 (coordinator_setup_shell.py:119)

tests/ also passes C901 (max 8) and PLR0912 (max 7), so those stay
gated there. PLR0913 (max 12, pytest fixtures) and PLR0915 (max 105,
integration scenarios) are ignored for tests/** because fixture
arguments and long scenarios are idiomatic and would only loosen the
production limits. PLR0913 does not conflict with Home Assistant
callback signatures at 7, so it stays enabled.

Refs #816

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Andrew Grimberg <tykeal@bardicgrove.org>
This commit is contained in:
Andrew GrimbergandCopilot committed 2026-11-02 12:26:47 -08:00
1 parent 71c1a62318
commit b8eb514ee8
1 file changed
+20
+20
View File
@@ -113,12 +113,32 @@ select = [
"I", # isort
"B", # flake8-bugbear
"C4", # flake8-comprehensions
"C90", # mccabe complexity
"PLR0912", # too many branches
"PLR0913", # too many arguments
"PLR0915", # too many statements
]
ignore = [
"E501", # line too long (handled by formatter)
"E203", # whitespace before ':'
]
# Complexity ratchet (#816): each limit equals the worst case measured
# in custom_components/ when the gate landed, so any growth fails.
# Lower these as functions are simplified; never raise them.
[tool.ruff.lint.mccabe]
max-complexity = 16
[tool.ruff.lint.pylint]
max-branches = 15
max-args = 7
max-statements = 46
[tool.ruff.lint.per-file-ignores]
# Pytest fixtures arrive as arguments and integration scenarios are
# long by design, so argument and statement counts are not gated there.
"tests/**" = ["PLR0913", "PLR0915"]
[tool.ruff.lint.isort]
force-single-line = true
force-sort-within-sections = true