Skip to content

chore: add pre-commit hooks (file hygiene, secrets, markdown, rust, commits) - #10

Merged
herata merged 5 commits into
mainfrom
feature/pre-commit
May 14, 2026
Merged

herata merged 5 commits into
mainfrom
feature/pre-commit

Conversation

@herata

@herata herata commented May 14, 2026 •

Copy link
Copy Markdown
Owner

What

pre-commit framework を使った hook 群を追加します。

Hook 構成

カテゴリ hook 効果
File hygiene trailing-whitespace, end-of-file-fixer, check-yaml/toml/json, check-merge-conflict, mixed-line-ending (LF), check-added-large-files (1 MiB cap) テキストファイルの基本衛生
Secrets gitleaks v8.21.2, detect-private-key secret 漏洩防止(agent が誤って token を含む config を push しないように)
Markdown markdownlint-cli2 v0.14.0 README 等のスタイル統一(日本語に配慮した relaxed config)
Commit message compilerla/conventional-pre-commit v3.6.0 commit-msg stage、Conventional Commits の 11 種 prefix を強制
Rust local cargo fmt --check / cargo clippy --all-targets -- -D warnings CI と同じ check をローカルで前倒し

追加ファイル

  • .pre-commit-config.yaml (94 行) — hooks 宣言
  • .markdownlint-cli2.yaml (12 行) — line-length / no-inline-html などを disable(日本語 README + jsonc fenced block 対応)

変更ファイル

  • .github/workflows/ci.yml — 新 job pre-commit を追加。libdbus を pre-install (cargo hook が keyring 経由で必要)、dtolnay rust-toolchain で rustfmt + clippy components を install、pre-commit/action@v3.0.1 を SHA pin で実行
  • README.md / README.ja.md — Development セクションに pre-commit install 手順を追加

Why

  • agent が日常的に commit する環境で、secret 漏洩 / 規約逸脱 / lint エラーを commit 段階で止める 価値が高い
  • CI で同じ check が動くので「local で pass → CI で pass」の整合性
  • mise ベースの開発フローと同じく、新規 contributor は pre-commit install 1 行で同一環境

Testing

  • mise exec -- cargo fmt --check → clean
  • mise exec -- cargo clippy --all-targets -- -D warnings → clean
  • ruby -ryaml -e ... で全 YAML (.pre-commit-config.yaml, .markdownlint-cli2.yaml, .github/workflows/ci.yml) の syntax 検証 → ok
  • CI で pre-commit run --all-files 通過確認 → 本 PR の CI で検証

Checklist

  • Conventional Commits 規約準拠 (chore: ...)
  • Self-review 済み
  • hook の SHA / rev は全て明示 pin(Dependabot で更新可能)
  • README 両言語に同等の手順を追加

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores

    • Enhanced CI to run formatting, linting, and docs checks as part of tests and added a dedicated pre-commit job to enforce hygiene and Rust checks on CI.
    • Added a pre-commit pipeline to validate formatting, linting, secret scanning, and commit-message conventions locally and in CI.
  • Documentation

    • Documented pre-commit setup and usage in the README (including local and CI workflows).
  • Style

    • Added a Markdown lint configuration with relaxed rules for the project.

Review Change Stack

…ommits)

Adds a pre-commit framework configuration with five hook groups:

- File hygiene: trailing-whitespace, end-of-file-fixer, check-yaml/toml/json,
  check-merge-conflict, mixed-line-ending (LF), detect-private-key,
  check-added-large-files (1 MiB cap).
- Secret detection: gitleaks v8.21.2.
- Markdown lint: markdownlint-cli2 with a relaxed config that disables
  rules that fight Japanese line widths and legitimate inline HTML.
- Conventional Commits validator: compilerla/conventional-pre-commit
  on the commit-msg stage with the standard 11-type allowlist.
- Rust local hooks: `cargo fmt --check` and `cargo clippy --all-targets
  -- -D warnings`, matching the CI gate.

CI runs the same set via the new `pre-commit` job (libdbus pre-installed
so the cargo hooks can build keyring's transitive deps; rustfmt + clippy
components pinned on the dtolnay toolchain action).

README and README.ja.md gained a "pre-commit hooks" subsection under
Development pointing contributors at `pre-commit install` plus the
`commit-msg` hook type.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented May 14, 2026 •

Copy link
Copy Markdown

Warning

Rate limit exceeded

@herata has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 54 minutes and 41 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c9bc1a32-1784-4b81-a16c-5252c460c9cd

📥 Commits

Reviewing files that changed from the base of the PR and between 438cd0b and c4010c6.

📒 Files selected for processing (1)
  • .github/workflows/ci.yml
📝 Walkthrough

Walkthrough

This PR adds a pre-commit hook framework to enforce code quality checks locally and in CI. It introduces a hook configuration pipeline, markdown linting rules, a new CI job, and developer documentation in both English and Japanese.

Changes

Pre-commit hook infrastructure

Layer / File(s) Summary
Hook configuration and linting rules
​.pre-commit-config.yaml, .markdownlint-cli2.yaml
Defines the full pre-commit pipeline: trailing whitespace and end-of-file hygiene, YAML/TOML/JSON validation, gitleaks secret scanning, markdownlint with relaxed rules (line length, inline HTML, bare URLs, first-line H1, duplicate headings, emphasis-as-heading), conventional commits validation on commit-msg, and local cargo fmt --check and cargo clippy Rust checks executed via mise exec.
CI workflow integration
.github/workflows/ci.yml
Updates jobs.test to run rustup/cargo steps via mise exec and adds a new pre-commit job that checks out the repo, installs libdbus-1-dev/pkg-config, sets up jdx/mise-action, ensures rustfmt/clippy, enables Rust cache, and runs pre-commit using pre-commit/action on each PR.
Developer documentation
README.md, README.ja.md
Documents one-time pre-commit setup, how to run hooks across tracked files, summarizes enabled checks (file hygiene, gitleaks, markdownlint, Conventional Commits, cargo fmt/cargo clippy), and notes CI runs the same hooks; provided in English and Japanese.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A framework fair, so clean and bright,
With hooks that guard both left and right—
Pre-commit checks the code with care,
From whitespace to clippy's keen stare,
Your pull requests now shine so fair! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding pre-commit hooks with specific categories (file hygiene, secrets, markdown, rust, commits).
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/pre-commit

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.pre-commit-config.yaml:
- Line 14: Update the pinned versions in .pre-commit-config.yaml for the listed
hooks: set pre-commit-hooks rev to v6.0.0, gitleaks rev to v8.30.1,
markdownlint-cli2 rev to v0.22.1, and conventional-pre-commit rev to v4.4.0;
locate the rev lines for each hook (references: "pre-commit-hooks", "gitleaks",
"markdownlint-cli2", "conventional-pre-commit") and replace the old tag strings
with the new versions, then run pre-commit autoupdate or a local pre-commit run
to verify there are no compatibility issues.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ca1f64f8-a1b1-4313-b4a6-324c26ac1ccc

📥 Commits

Reviewing files that changed from the base of the PR and between 1ec8118 and 141c5c3.

📒 Files selected for processing (5)
  • .github/workflows/ci.yml
  • .markdownlint-cli2.yaml
  • .pre-commit-config.yaml
  • README.ja.md
  • README.md

Comment thread .pre-commit-config.yaml Resolved
herata and others added 3 commits May 14, 2026 18:14
CI's pre-commit job failed on the first run for two reasons:

1. markdownlint flagged six MD040/MD032 violations in
   docs/superpowers/{plans,specs}/*.md — those are internal
   brainstorming / implementation notes, not user-facing docs.
   Add `docs/superpowers/**` to the markdownlint ignore list.

2. The local cargo hooks used plain `cargo`, which resolves through
   the host's rustup default. On the contributor machine that ended
   up being a stale 1.80.1 toolchain even though `mise.toml` pins
   1.89, so the hook errored with "rustc 1.80.1 is not supported".
   Route both cargo hooks through `mise exec --` so the pinned
   toolchain is always used.

CI's pre-commit job now installs mise (with GITHUB_TOKEN for the ubi
backend rate limit), then `rustup component add rustfmt clippy`
guarantees the components are present.

Local verification: `pre-commit run --all-files` now passes all 13
hooks (file hygiene, gitleaks, markdownlint, cargo fmt, cargo clippy).
The `commit-msg` hook is also installed so this very commit went
through the conventional-pre-commit validator.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Address CodeRabbit's review on PR #10: the pinned hook revs were stale.
Ran `pre-commit autoupdate` and bumped:

  - pre-commit-hooks       v5.0.0  -> v6.0.0
  - gitleaks               v8.21.2 -> v8.30.0
  - markdownlint-cli2      v0.14.0 -> v0.22.1
  - conventional-pre-commit v3.6.0 -> v4.4.0

markdownlint-cli2 v0.22 enabled MD060/table-column-style by default,
which fires on every row of README/README.ja.md tables that mix
full-width Japanese characters with ASCII. Pipe alignment for those
tables would only be byte-accurate, not visually accurate, so disable
the rule in `.markdownlint-cli2.yaml` with a comment.

Local `pre-commit run --all-files` passes all 13 hooks.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
macos test failed at the clippy step with `error: unexpected argument
'clippy' found`. The previous `rustup component add rustfmt clippy`
step had rustup install a *fresh* 1.89 toolchain (separate from the
mise-managed one) and dropped the components there. The next step
called `cargo clippy` via the mise toolchain, which did not see
clippy.

Run every cargo / rustup invocation in the test matrix through
`mise exec --` so all OSes use the mise-managed toolchain
consistently. No change to deny / msrv / linux-headless jobs.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/workflows/ci.yml:
- Around line 95-97: The step "ensure rustfmt + clippy components" in the
pre-commit job installs components into the default toolchain; change that to
install into the mise toolchain so hooks run against the same toolchain—replace
the current run command with one that targets the mise toolchain (for example
use rustup +mise component add rustfmt clippy or rustup component add
--toolchain mise rustfmt clippy) so cargo fmt/clippy are installed into the mise
toolchain used by the pre-commit hooks.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 275ef592-d9d9-4d1a-b77e-41415efa5c4f

📥 Commits

Reviewing files that changed from the base of the PR and between 141c5c3 and 438cd0b.

📒 Files selected for processing (3)
  • .github/workflows/ci.yml
  • .markdownlint-cli2.yaml
  • .pre-commit-config.yaml
🚧 Files skipped from review as they are similar to previous changes (1)
  • .pre-commit-config.yaml

Comment thread .github/workflows/ci.yml Resolved
…up through mise

Two related fixes:

1. test (macos-latest) kept failing with `cargo clippy: unexpected
   argument 'clippy' found` because `mise exec -- rustup component add`
   on macOS spun up a *separate* rustup 1.89 toolchain (the host's
   pre-installed rustup, not mise's), and the subsequent
   `mise exec -- cargo clippy` resolved to mise's cargo which never
   saw the new components. The test matrix only needs rust +
   cargo-nextest, so drop mise from that job and install rust via
   `dtolnay/rust-toolchain` with explicit `components: rustfmt, clippy`.
   This is what the pre-commit job already implied: mise is only for
   the cargo hooks invoked from `pre-commit run`, not for the cargo
   commands the test matrix runs directly.

2. CodeRabbit flagged that the pre-commit job's `rustup component add
   rustfmt clippy` runs against the host's rustup, which can diverge
   from the mise toolchain that the pre-commit cargo hooks
   (`mise exec -- cargo ...`) actually use. Route that rustup
   invocation through `mise exec` so the components land in the same
   toolchain.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@herata
herata merged commit f429eec into main May 14, 2026
8 checks passed
@herata
herata deleted the feature/pre-commit branch May 14, 2026 11:58
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.

1 participant