ci: lint Python and shell scripts with ruff and shellcheck #112

Closed
opened 2026-11-13 22:33:00 +00:00 by Claude · 0 comments
Owner

Decided in #91 (part of the map #87). No hook or CI job lints the Python or shell in this repository today: about 1,260 lines under scripts/ and tests/scripts/ plus scripts/dev-setup.sh are held by review alone. This issue adds the two standard tools as controls. It depends on no other open decision.

Add

  • ruff as pre-commit hooks from its official hook repository: the linter and the formatter.
    • Configuration in one committed file, ruff.toml, at the repository root. Use ruff's defaults and additionally select the complexity and function-size rules (C901, PLR0912, PLR0915) at their default thresholds. Do not tune a threshold in this issue.
    • ruff.toml is a new top-level file: add it to build_ignore in galaxy.yml.
  • shellcheck as a pre-commit hook (the shellcheck-py hook, so no system package is needed), at its default severity, with no .shellcheckrc unless a finding requires one.
  • Both run in CI through the existing Lint job, which already runs the pre-commit hooks. No new workflow and no new script.

Fix what they find

  • Format the existing Python with ruff format in its own commit, separate from any hand edits, so the diff is reviewable.
  • Fix lint findings where the fix is small and safe.
  • Where a finding is not worth fixing now, suppress it inline with the rule code and a reason (# noqa: C901 reason, # shellcheck disable=SC… reason). No global ignore of a rule.
  • scripts/check_image_versions.py, scripts/bump_image_versions.py and scripts/check_bot_pr_diff.py may be removed or rewritten by #96. Do not restructure them here. If one needs more than a handful of complexity suppressions, use a per-file entry for that file in ruff.toml with a comment naming #96, and list it in the pull request.

Notes

  • .pre-commit-config.yaml is an image input: this is the two-PR loop. The first pull request carries the hook change and the PATCH bump of the ci image version (scripts/bump_image_versions.py); the consumer pins move in a second pull request after the image is built on main.
  • Each pushed image layer must stay under 100 MB. The new hook environments are baked into the ci image; check the layer sizes the build prints.
  • Renovate already follows hook rev: lines, so the new hooks need no Renovate change. renovate.json is not touched.
  • No changelog fragment: nothing a consumer installs changes.
  • The existing script tests under tests/scripts/ must still pass after formatting and fixes.

Not in this issue

  • A check for comment length or file length: decided against in #91 (no standard tool, no custom checker).
  • ansible-lint's complexity rule: #93 sets its number.
  • Writing the code-style document: waits for #103.

Acceptance

  • pre-commit run --all-files passes locally with the new hooks, and the Lint check passes on the pull request.
  • A deliberately bad change (an unused import in a script, an unquoted variable in dev-setup.sh) makes the corresponding hook fail; say in the pull request that this was tried.
  • Every suppression carries a rule code and a reason.
Decided in #91 (part of the map #87). No hook or CI job lints the Python or shell in this repository today: about 1,260 lines under `scripts/` and `tests/scripts/` plus `scripts/dev-setup.sh` are held by review alone. This issue adds the two standard tools as controls. It depends on no other open decision. ## Add - **`ruff`** as pre-commit hooks from its official hook repository: the linter and the formatter. - Configuration in one committed file, `ruff.toml`, at the repository root. Use ruff's defaults and additionally select the complexity and function-size rules (`C901`, `PLR0912`, `PLR0915`) at their default thresholds. Do not tune a threshold in this issue. - `ruff.toml` is a new top-level file: add it to `build_ignore` in `galaxy.yml`. - **`shellcheck`** as a pre-commit hook (the `shellcheck-py` hook, so no system package is needed), at its default severity, with no `.shellcheckrc` unless a finding requires one. - Both run in CI through the existing Lint job, which already runs the pre-commit hooks. No new workflow and no new script. ## Fix what they find - Format the existing Python with `ruff format` in its own commit, separate from any hand edits, so the diff is reviewable. - Fix lint findings where the fix is small and safe. - Where a finding is not worth fixing now, suppress it inline with the rule code and a reason (`# noqa: C901 reason`, `# shellcheck disable=SC… reason`). No global ignore of a rule. - `scripts/check_image_versions.py`, `scripts/bump_image_versions.py` and `scripts/check_bot_pr_diff.py` may be removed or rewritten by #96. Do not restructure them here. If one needs more than a handful of complexity suppressions, use a per-file entry for that file in `ruff.toml` with a comment naming #96, and list it in the pull request. ## Notes - `.pre-commit-config.yaml` is an image input: this is the two-PR loop. The first pull request carries the hook change and the PATCH bump of the `ci` image version (`scripts/bump_image_versions.py`); the consumer pins move in a second pull request after the image is built on `main`. - Each pushed image layer must stay under 100 MB. The new hook environments are baked into the `ci` image; check the layer sizes the build prints. - Renovate already follows hook `rev:` lines, so the new hooks need no Renovate change. `renovate.json` is not touched. - No changelog fragment: nothing a consumer installs changes. - The existing script tests under `tests/scripts/` must still pass after formatting and fixes. ## Not in this issue - A check for comment length or file length: decided against in #91 (no standard tool, no custom checker). - ansible-lint's `complexity` rule: #93 sets its number. - Writing the code-style document: waits for #103. ## Acceptance - `pre-commit run --all-files` passes locally with the new hooks, and the Lint check passes on the pull request. - A deliberately bad change (an unused import in a script, an unquoted variable in `dev-setup.sh`) makes the corresponding hook fail; say in the pull request that this was tried. - Every suppression carries a rule code and a reason.
Claude added the
Status
Ready for Agent
label 2026-11-13 22:33:00 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Mortis/Kamino#112