Chore: Pin ruff rule selection - #39
Conversation
There was a problem hiding this comment.
Pull request overview
Pins a stable Ruff lint rule selection for this repository (and downstream consumers), preventing unexpected lint expansions from Ruff version bumps and aligning the template with the org’s de-facto rule set. Also updates pre-commit Ruff hooks to lint all Python/pyi files by default rather than a narrow, error-prone path regex.
Changes:
- Add
.ruff.tomlto explicitly pinlint.selectand key ignores (E501,B008), plus test-only per-file ignores. - Remove the
files:regex restriction fromruffandruff-formathooks in.pre-commit-config.yamlso Ruff applies to all Python/pyi files by default.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
.ruff.toml |
Introduces explicit Ruff configuration to stabilize lint behavior across Ruff releases and codify baseline org rules. |
.pre-commit-config.yaml |
Removes overly restrictive Ruff hook files: filters so Python linting is not accidentally skipped for common layouts (e.g., src/). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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 <noreply@anthropic.com>
Signed-off-by: Matthew Watkins <mwatkins@linuxfoundation.org>
ed7afef to
f51f111
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
.ruff.toml:17
- Wording is unclear here: “decline” reads like a typo/misuse in this context. If the intent is to say pinning doesn’t reject other rule families long-term (it just makes enabling them deliberate), consider rephrasing for clarity.
# Pinning does not decline the unselected rules. It makes adopting them a
# deliberate, reviewed change instead of a side effect of a version bump.
tykeal
left a comment
There was a problem hiding this comment.
🤖 Dependamerge
Approved this pull request ✅
Why
This repo carries the ruff hook but no ruff configuration, so it runs whatever ruff's default rule set happens to be. That default is not stable across releases — verified directly:
A 7× expansion in a patch-level bump. The routine
pre-commit autoupdatethat crossed it broke 15 repositories in this org simultaneously, on code nobody had touched — 54 lint violations plus 71 lines of autofix, all on files that were 100% clean the day before.Despite the name, this repo is not currently a Python house-style reference: it contains no
pyproject.tomland no ruff config. Given it is where consumers look for the org's Python conventions, it is worth it being one.What
1.
.ruff.tomlpinning the rule setNot invented — this is the de-facto house style, present as a superset in 13 of the 16 org repos that already pin their rules.
E501+B008are ignored in 14 and 13 of those 16 respectively.A standalone
.ruff.tomlrather than[tool.ruff]because this repo has nopyproject.toml.Pinning does not decline the unselected rules. It makes adopting
SIM,BLE,PIEand friends a deliberate, reviewed change rather than a side effect of a version bump.2.
line-lengthandtarget-versiondeliberately left unsetBoth would change existing behaviour rather than just pinning it —
target-versionalters whichpyupgraderules fire, andline-lengthdrives the formatter. Ruff's defaults (and its inference fromrequires-python) continue to apply unchanged. Standardising those is separate work.3. The
files:pattern dropped from both ruff hooksThe inherited pattern was:
Two defects:
src/, so any repo in a src layout has its entire package silently unlinted. This is not hypothetical — 9 repos are affected, includingproject-reporting-tool(81 files),gerrit-clone-action(33) anddependamerge(36). Three repos (aislop-scan-action,sigul-sign-docker,zizmor-scan-action) currently lint nothing at all.custom_components/is a Home Assistant artifact that exists in zero repos in this org, yet has propagated to 103 of them.The smoking gun: several repos carry
per-file-ignoresfor paths the hook can never reach —gerrit-clone-actionhas 7 entries forsrc/gerrit_clone/*.py. Someone wrote config for files ruff was never shown.Removing
files:restores the upstream hook default (types_or: [python, pyi]), i.e. lint all Python.Validation
ruff check --show-settingsconfirms enabled categories drop from 38 toB C E F I UP Wpre-commit run --all-files→ all hooks pass, includingreuse linton the new filefiles:change is inert hereScope
This is step 1 of a sequenced rollout, applied identically to
actions-template,workflows-templateandpython-workflows. Steps 2–3 pinselectin the 14 exposed repos that do contain Python and addPLR0917to the 3 that already selectPL. Fixingfiles:in existing repos is deliberately last, since it surfaces previously-unlinted code and must land afterselectis pinned.