Skip to content

Chore: Pin ruff rule selection - #147

Merged
askb merged 1 commit into
lfreleng-actions:mainfrom
modeseven-lfreleng-actions:chore/pin-ruff-rule-selection
Jul 30, 2026
Merged

Chore: Pin ruff rule selection#147
askb merged 1 commit into
lfreleng-actions:mainfrom
modeseven-lfreleng-actions:chore/pin-ruff-rule-selection

Conversation

@ModeSevenIndustrialSolutions

@ModeSevenIndustrialSolutions ModeSevenIndustrialSolutions commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Why

This repo runs the ruff hook with no ruff configuration, so it applies whatever ruff's default rule set happens to be. That default is not stable across releases — verified directly:

$ ruff 0.15.22 check --show-settings --isolated
 59 rules across  2 categories (E, F)

$ ruff 0.16.0 check --show-settings --isolated
413 rules across 38 categories

A 7× expansion in a patch-level bump. The routine autoupdate that crossed it broke 15 repos in this org simultaneously on untouched code — including this one, where #146 is blocked on 5 violations.

What

[lint]
select = ["E", "W", "F", "I", "B", "C4", "UP"]
ignore = ["E501", "B008"]

Not invented — this is the de facto house style, a superset in 13 of the 16 org repos that already pin their rules.

A standalone .ruff.toml because this repo has no pyproject.toml.

Selecting these categories switches every other rule off — that is the point. Adopting them becomes a deliberate, reviewed change rather than a side effect of a version bump.

line-length and target-version are left unset on purpose — both would change behaviour rather than pin it (target-version alters which pyupgrade rules fire). Standardising those is separate work.

Effect on #146

All 5 blocking violations fall outside the pinned set and cease to exist:

Rule Count In core-7?
EXE001 2 No — EXE not selected
PIE810 1 No — PIE not selected
BLE001 1 No — BLE not selected
SIM115 1 No — SIM not selected

The last two were the ones needing a judgement call: BLE001 wraps a tomllib.load, and SIM115 flags the emit() helper's conditional file handle (open(...) if target else sys.stdout), which already has correct try/finally cleanup and simply cannot be expressed as a plain context manager. This removes the need to contort either.

Validation

  • No code changes needed — verified clean under the pinned set with ruff 0.16.0 against the files the hook selects
  • ruff check --show-settings confirms enabled categories drop from 38 to B C E F I UP W
  • pre-commit run --all-files → all hooks pass

@ModeSevenIndustrialSolutions
ModeSevenIndustrialSolutions requested review from a team and Copilot July 28, 2026 14:09
@github-actions github-actions Bot added the chore Code chores (dependency updates, etc) label Jul 28, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an explicit Ruff configuration file to pin the enabled lint rule set, preventing Ruff’s evolving defaults from causing unexpected lint failures on version bumps.

Changes:

  • Introduces .ruff.toml with an explicit [lint].select set (E, W, F, I, B, C4, UP) and targeted ignores (E501, B008).
  • Adds lint.per-file-ignores for tests/**/*.py to reduce test-only noise when the selected ruleset is widened later.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread .ruff.toml Outdated
Comment thread .ruff.toml Outdated
tykeal
tykeal previously approved these changes Jul 28, 2026

@tykeal tykeal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Dependamerge
Approved this pull request ✅

Copilot AI review requested due to automatic review settings July 28, 2026 16:50

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

.ruff.toml:41

  • The file currently ends with a whitespace-only line, which will be flagged by the existing trailing-whitespace pre-commit hook. Remove the trailing whitespace/extra blank line so the repo stays clean under pre-commit.
"tests/**/*.py" = ["S101", "ARG", "PLR0913", "PLR0917", "PLR2004"]

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (2)

.ruff.toml:18

  • The comment text "Pinning does not decline the unselected rules" is misleading/awkward here: with a select list, Ruff disables all unselected rules, so this can read as if unselected rules still run. Reword to make it explicit that unselected rules are switched off, and that adding more rules later is a deliberate config change.
# Pinning does not decline the unselected rules.  It makes adopting them
# a deliberate, reviewed change instead of a side effect of a version
# bump.

.ruff.toml:24

  • "de-facto" is typically written as "de facto" (no hyphen) in standard usage, including attributive use.
# The de-facto standard across this organisation: present as a superset

This repository runs the ruff hook with no ruff configuration, so it
applies 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 crossing that boundary changed which
rules run and broke fifteen repositories in this organisation at once,
on code nobody had touched.  Ninety-six repositories carry the hook
with no configuration, so all of them are exposed to the next bump.

Pin 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.

No code changes accompany this: the tree is already clean under the
pinned rule set, verified with ruff 0.16.0 against the files the hook
currently selects.

Co-authored-by: Claude <noreply@anthropic.com>
Signed-off-by: Matthew Watkins <mwatkins@linuxfoundation.org>
@askb
askb merged commit 74b171e into lfreleng-actions:main Jul 30, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore Code chores (dependency updates, etc)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants