From f51f11158de3fd9bb06c79094a74afd9c5f8e398 Mon Sep 17 00:00:00 2001 From: Matthew Watkins Date: Tue, 28 Jul 2026 15:00:15 +0100 Subject: [PATCH] Chore: Pin ruff rule selection Repositories created from this template inherit the ruff hook but no ruff configuration, so they run whatever ruff's *default* rule set happens to be. That default is not stable across releases: ruff 0.15.22 -> 59 rules across 2 categories (E, F) ruff 0.16.0 -> 413 rules across 38 categories A routine pre-commit autoupdate therefore changed which rules run and broke fifteen repositories in this organisation at once, on code that nobody had touched. Ninety-six repositories currently carry the hook with no configuration, so they are all exposed to the next bump. Add a .ruff.toml pinning the rule set to the de-facto house style, which appears as a superset in 13 of the 16 repositories that already pin their own. This does not decline the unselected rules; it makes adopting them a deliberate, reviewed change rather than a side effect of a version bump. line-length and target-version are left unset on purpose. Both alter existing behaviour -- target-version changes which pyupgrade rules fire -- and the aim here is to fix which rules run, nothing else. Also drop the ruff hooks' files pattern so ruff lints all Python, per the upstream hook default. The inherited pattern was ^(scripts|tests|custom_components)/.+\.py$ which omits src/ and so silently skips the entire package in a src layout. It also names custom_components, a Home Assistant artifact that exists in no repository in this organisation. Co-authored-by: Claude Signed-off-by: Matthew Watkins --- .pre-commit-config.yaml | 2 -- .ruff.toml | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 .ruff.toml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9e66823..cc7f998 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -55,10 +55,8 @@ repos: rev: cb8c523fd4835aba42af70f4cad5568db4df0b6c # frozen: v0.16.0 hooks: - id: ruff - files: ^(scripts|tests|custom_components)/.+\.py$ args: [--fix, --exit-non-zero-on-fix] - id: ruff-format - files: ^(scripts|tests|custom_components)/.+\.py$ - repo: https://github.com/pre-commit/mirrors-mypy rev: 41e691678310dfd3833f7ab4e180ddb014310356 # frozen: v2.3.0 diff --git a/.ruff.toml b/.ruff.toml new file mode 100644 index 0000000..e8050e3 --- /dev/null +++ b/.ruff.toml @@ -0,0 +1,41 @@ +# SPDX-License-Identifier: Apache-2.0 +# SPDX-FileCopyrightText: 2026 The Linux Foundation + +# Ruff configuration for repositories created from this template. +# +# The `select` list is pinned deliberately. Without it ruff applies its +# *default* rule set, and that default is not stable across releases: +# +# ruff 0.15.22 -> 59 rules across 2 categories (E, F) +# ruff 0.16.0 -> 413 rules across 38 categories +# +# A routine pre-commit autoupdate therefore changed which rules run and +# broke fifteen repositories in this organisation simultaneously, on code +# that had not been touched. +# +# Pinning does not decline the unselected rules. It makes adopting them a +# deliberate, reviewed change instead of a side effect of a version bump. +# +# `line-length` and `target-version` are intentionally left unset so that +# ruff's own defaults -- and its inference from `requires-python` where a +# `pyproject.toml` exists -- continue to apply unchanged. + +[lint] +# The de-facto standard across this organisation: present as a superset in +# 13 of the 16 repositories that already pin their rules. +select = ["E", "W", "F", "I", "B", "C4", "UP"] + +ignore = [ + "E501", # line-too-long: the formatter owns line length + "B008", # function call in argument default: typer/click idiom +] + +[lint.per-file-ignores] +# Test suites legitimately break rules that matter in library code. +# Listed even though some are not currently selected, so that widening +# `select` later does not immediately flag every test module. +# +# PLR0917 in particular cannot be satisfied in tests that stack +# `@patch` decorators: unittest.mock injects its mocks positionally, so a +# keyword-only signature is impossible, not merely inconvenient. +"tests/**/*.py" = ["S101", "ARG", "PLR0913", "PLR0917", "PLR2004"]