Skip to content

Adopt ruff for linting and formatting, replacing flake8 (#469) - #470

Merged
squid-protocol merged 1 commit into
mainfrom
chore/ruff-adoption
Jul 25, 2026
Merged

squid-protocol merged 1 commit into
mainfrom
chore/ruff-adoption

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Summary

Replaces flake8 (which only ever ran a minimal E9/F63/F7/F82 syntax-floor check in CI, never real linting) with ruff, using the same baseline-gated pattern established for mypy (#430) and dead_key_audit.py (#325).

Rule selection (measured actual hit counts against this codebase before deciding, not guessed):

  • Included: E/W, F, B, C4, SIM, I, ARG, UP (target-version py39), S (bandit security -- this project IS a security scanner, dogfooding value is obvious, and only 47 hits), PERF, DTZ, A, RSE, RUF.
  • Excluded after measuring: BLE/TRY (80+53 hits, almost entirely flagging this codebase's deliberate except Exception: fault-isolation pattern, not bugs), D (528, docstring style doesn't match any standard convention), T20 (411, this is a CLI-heavy toolkit -- most print() calls are legitimate output), G (242, f-string-vs-%-style logging is genuinely mixed by design), ANN (redundant with the mypy epic). E501 was also excluded -- already ignored in the old .flake8 config, and at 464/705 raw findings would've been ~66% of the baseline alone.

One-time cleanup before baselining (so the backlog doesn't start already rotten):

  • ruff check --fix: 500 safe autofixes.
  • ruff check --select=UP006,UP035 --fix --unsafe-fixes: 581 PEP 585 typing modernizations (Dict/List/etc -> dict/list/etc). Marked "unsafe" by ruff's own conservatism, confirmed safe here (project requires Python >=3.9; full mypy re-run afterward is still clean).
  • ruff format: 29 files reformatted (replaces the vestigial [tool.black] config that was never actually wired into anything).
  • Full 866-test pytest suite re-run clean -- no behavioral changes, purely mechanical.

Baseline after cleanup: 241 findings / 240 unique keys across 27 rule families, none dominant (largest is SIM102 at 17).

CI changes:

  • New ruff-audit.yml: baseline-gated lint + zero-tolerance ruff format --check (zero-tolerance since there's no backlog to carry after the repo-wide reformat). Ruff's version is pinned (unlike mypy-audit.yml's unpinned mypy) since ruff ships new rules much more frequently -- an unpinned version could silently add findings on an unrelated PR.
  • smoke-test.yml: flake8's syntax-floor step replaced with the ruff equivalent (F63/F7/F82, same pyflakes numbering), still running across the full OS/Python-version matrix.
  • gitgalaxy/requirements.txt: flake8 + orphaned transitive deps (mccabe, pycodestyle, pyflakes) removed, ruff added.

Epic: #469

Test plan

  • mypy gitgalaxy/ --ignore-missing-imports: still Success: no issues found in 65 source files after the mass typing modernization
  • python tests/mypy_audit.py --ci: passes
  • python tests/dead_key_audit.py --ci: no new findings
  • python tests/ruff_audit.py --ci: passes against the new 240-key baseline
  • All .py files under gitgalaxy/ still parse (ast.parse sweep)
  • Full pytest tests/ -q: 866 passed, 1 deselected, 1 xfailed -- identical to pre-change

🤖 Generated with Claude Code

Replaces flake8 (which was only ever running a minimal E9/F63/F7/F82
syntax floor check, never real linting -- see .flake8's own
extend-ignore list) with ruff, using the same baseline-gated CI
pattern established for mypy (#430) and dead_key_audit.py (#325):
tests/ruff_audit.py + ruff_audit_baseline.json, wired into a new
.github/workflows/ruff-audit.yml.

RULE SELECTION (pyproject.toml [tool.ruff.lint])
Deliberately scoped, not `ALL` -- measured actual hit counts against
this codebase before deciding what to include:

- Included: E/W (pycodestyle), F (pyflakes), B (bugbear), C4
  (comprehensions), SIM (simplify), I (isort), ARG (unused args), UP
  (pyupgrade, target-version py39), S (bandit security -- this project
  IS a security scanner, so dogfooding it on its own code has obvious
  value, and it was only 47 hits, not noisy), PERF, DTZ (naive
  datetime), A (builtins), RSE (raise), RUF (ruff-specific).
- Excluded after measuring: BLE/TRY (80+53 hits, but sampling showed
  they're almost entirely flagging this codebase's *deliberate*
  `except Exception:` fault-isolation pattern -- documented
  "DEFENSIVE ARCHITECTURE" design throughout, not bugs) -- enabling
  them would've buried real signal under intentional-design noise.
  D (528, docstring-style enforcement against a prose-docstring
  convention that matches no standard style). T20 (411, this is a
  CLI-heavy toolkit -- most print() calls are legitimate user-facing
  output). G (242, f-string-vs-%-style logging is genuinely mixed by
  design already, not clearly wrong). ANN (redundant with the mypy
  epic just completed). E501 (line-too-long) was ALSO explicitly
  ignored in the old .flake8 config already, and at 464 of the initial
  705 raw findings would have been ~66% of the baseline on its own,
  drowning out the other 27 rule families' genuinely diverse findings.

ONE-TIME REPO CLEANUP (before baselining, so it doesn't rot forever)
- `ruff check --fix`: 500 safe autofixes (import sorting, trailing
  whitespace, redundant open() modes, etc).
- `ruff check --select=UP006,UP035 --fix --unsafe-fixes`: 581 PEP 585
  typing modernizations (Dict/List/Set/Tuple -> dict/list/set/tuple).
  Marked "unsafe" by ruff's own conservatism, but confirmed safe here:
  this project requires Python >=3.9 (PEP 585 generics work natively
  at runtime from 3.9 on), and a full `mypy` re-run afterward is still
  clean (Success: no issues found in 65 source files).
- `ruff format`: 29 files reformatted to a consistent style (replaces
  the vestigial [tool.black] config, which was configured but never
  actually wired into anything).
- Full 866-test pytest suite re-run clean after all of the above --
  no behavioral changes, only mechanical ones.

Baseline after cleanup: 241 findings / 240 unique keys across 27 rule
families, none dominant (largest is SIM102 at 17).

CI CHANGES
- New ruff-audit.yml: baseline-gated lint (240-key baseline) +
  zero-tolerance `ruff format --check` (zero-tolerance because the
  whole repo was just reformatted, so there's no backlog to carry --
  letting it drift would just mean redoing this same cleanup later).
  Ruff's version is pinned here (unlike mypy-audit.yml's unpinned
  `pip install mypy`) because ruff ships new lint rules far more
  frequently than mypy does; an unpinned version could silently add
  baseline findings on a PR that touched no lint-relevant code.
- smoke-test.yml: flake8's syntax-floor step replaced with the ruff
  equivalent (same F63/F7/F82 codes -- ruff kept pyflakes' numbering),
  still running across the full OS/Python-version matrix as a
  cross-platform floor check, distinct in purpose from ruff-audit.yml's
  single-environment broader lint.
- gitgalaxy/requirements.txt: flake8 and its now-orphaned transitive
  deps (mccabe, pycodestyle, pyflakes) removed, ruff added.
Comment on lines +18 to +21
from gitgalaxy.standards.language_standards import (
LANGUAGE_DEFINITIONS, # noqa: F401
LENS_CONFIG,
)
@github-actions

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

@squid-protocol
squid-protocol merged commit f1cacf0 into main Jul 25, 2026
38 of 39 checks passed
@squid-protocol
squid-protocol deleted the chore/ruff-adoption branch July 25, 2026 20:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants