ci: add a ruff lint gate, and clear what it found - #135
Conversation
Nothing checked for unused imports, undefined names or unreachable code here, and turning the check on surfaced nine findings that had to be cleared first so the gate starts green. Eight were unused imports — one in junos_ops/common.py and seven across the tests. The source one was verified not to be a re-export before removal: cli.py and rsi.py import ConnectClosedError straight from jnpr.junos.exception, and common.py declares no __all__, so nothing was reading it through that module. The ninth was `l` as a comprehension variable in tests/test_check.py, renamed to `line`. select is stated rather than inherited: ruff's default set is not stable across releases (0.16 widened it to UP, B, SIM, BLE, RUF), so relying on the default means going red on an upgrade without any of this code changing. Sibling repositories pass with no select only because their lockfiles hold them on 0.15. The CI pin covers the other half. ruff format is not gated; ruff.toml records why. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YVg3toYKK6J2J9ggdrzYVf
AI review (gpt-5.6-sol)
Advisory first-pass review generated by ai-review.yml — verify findings before acting. |
|
The mechanism is right and I had not considered it — my check was "nothing in this repository reads it", which says nothing about downstream consumers. Without I am not restoring it, for two reasons.
The suggested remedy would create the commitment rather than preserve it. What would change the answer: |
This repository had no ruff configuration and no lint step. Turning the check
on surfaced nine findings, cleared here so the gate starts green.
What it found
F401unused importjunos_ops/common.py, 7 acrosstests/E741ambiguous nameltests/test_check.pycomprehensionlineThe source-file one was checked before removing rather than auto-fixed on
trust:
ConnectClosedErrorcould plausibly have been imported intocommon.pyas a re-export. It is not —cli.pyandrsi.pyimport itstraight from
jnpr.junos.exception, andcommon.pydeclares no__all__,so nothing reached it through that module. 379 tests pass after the change.
Why
selectis stated rather than inheritedRuff's default rule set is not stable across releases. 0.16 widened it to
include
UP,B,SIM,BLEandRUF, so a repository relying on thedefault goes red on an upgrade without a line of its own code changing.
That is not hypothetical: the sibling repositories that already run
ruff check .with noselectpass only because their lockfiles hold them on0.15.x. Pinning the ruff version alone does not fix it, it defers it to
whoever bumps the pin. The version is pinned in CI as well, so both failure
modes are covered.
Why
ruff formatis not gatedRecorded in
ruff.toml. It would rewrite 22 of 37 files here — a reformatcommit of its own, and a decision separate from turning linting on.
line-lengthis left unset for the same reason.Noticed, not changed
except (ConnectClosedError, Exception):appears throughoutcli.pyandrsi.py. The tuple is redundant —Exceptionalready catchesConnectClosedError— so the specific name reads as intent that the code doesnot actually express. Pre-existing and outside this change; worth a look on
its own.
Verification
Run with the pinned 0.16.0, the same command CI runs: clean. Then broken on
purpose — an unused import and an undefined name are both reported, and the
gate returns to green once removed.
🤖 Generated with Claude Code
https://claude.ai/code/session_01YVg3toYKK6J2J9ggdrzYVf