Skip to content

refactor: apply the template's numeric lint rules - #166

Merged
furedea merged 6 commits into
mainfrom
refactor/apply-numeric-lint
Oct 21, 2026
Merged

furedea merged 6 commits into
mainfrom
refactor/apply-numeric-lint

Conversation

@furedea-agent

@furedea-agent furedea-agent Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

概要

template-rust と同じ数値系 lint と,lefthook の file-length(500 行)を導入しました.既存の違反は,挙動を変えないリファクタですべて解消しています.#[allow] / #[expect] は追加していません.

導入した clippy の設定は次のとおりです.

  • all / pedantic
  • too-many-arguments-threshold 3
  • excessive-nesting-threshold 2
  • cognitive-complexity-threshold 15
  • allow_attributes_without_reason

あわせて,Rust のモジュールディレクトリ(snake_case)が ls-lint の .dir ルールに違反していた既存の問題も直しました.

Refs furedea/dotfiles#247

違反数

種別 導入前 導入後
clippy::excessive_nesting 149 0
clippy::too_many_arguments 24 0
clippy::cognitive_complexity 2 0
その他の pedantic(needless_pass_by_value 6,format_push_string 3 など) 20 0
clippy 合計(cargo clippy --all-targets) 195 0
500 行超のファイル 6 0
ls-lint(引数なし)の .dir 違反(src/github_app) 1 0

500 行を超えていたのは次の 6 ファイルです.

  • skills.rs(804 行)
  • github_app.rs(668 行)
  • hooks.rs(613 行)
  • cli.rs(525 行)
  • tests/neutral_generated_artifacts.rs(868 行)
  • tests/external_hook_bundles.rs(653 行)

受け入れ条件

  • template と同じ数値ルールが Cargo.toml / clippy.toml と lefthook(file-length)に入っている
  • 違反ゼロ,理由のない抑止属性なし(抑止属性の提案もなし)
  • 挙動を変えない分割のみで,既存テストが通る
  • Codex の adversarial review の指摘(medium 1 件)を修正した
  • CI の rust-audit が通る(fix(deps): update rustls-webpki and webpki-roots for security advisories #167 のマージ後に origin/main へ rebase し,c64eb26 で CI の全チェックが pass)

詳細

設定

  • Cargo.toml: [lints.clippy] に,template と同じ次のルールを追加しました.既存の dbg_macro などの deny は残しています.
    • all / pedantic
    • allow_attributes_without_reason
    • cognitive_complexity
    • excessive_nesting
  • clippy.toml: template のファイルをそのまま追加しました.
  • lefthook.yml: template の file-length コマンドを追加しました.
  • .ls-lint.yml: template-rust と同じ構造に揃えました.
    • ルート直下のファイル規則を YAML anchor(<<: &files)にまとめました.
    • src: ブロックでは <<: *files でその規則を取り込み,.dir: regex:[a-z0-9]+(_[a-z0-9]+)* を指定しました.
    • ls-lint v2 では,ネストしたブロックがルートの規則を引き継がずに置き換えます.そのため .dir だけを書くと,src 配下のファイル名規則が黙って外れます.
    • tests/ を含む src 以外のディレクトリは,kebab-case のままです.

ls-lint の確認(一時ファイル・ディレクトリは確認後に削除済み)

ケース 結果
引数なしの ls_lint pass
一時的な src/bad-dir fail(.dir)
一時的な src/good_dir pass
一時的な src/BadFile.rs fail(.*.src 配下でもファイル規則が効いている)
一時的な tests/bad_dir fail(kebab-case のまま)

リファクタ方針

  • ネストの解消: 閾値 2 では,impl と mod tests もネストに数えられます.そのため,メソッド本体の if / for / 複数行クロージャはそれだけで違反になります.
    • 分岐は module 直下の関数へ移しました.
    • if … bail! は ensure! に置き換えました.
  • 引数過多の解消: 一緒に渡される値を,小さな構造体にまとめました.
    • GenerationContext { source, external_hooks, runtime_root }
    • SkillTarget { provider, path }
    • MintedToken { token, issuer }
    • CommandRelocation,CommandNormalization,HookLocation
  • 500 行超のファイル: 次のどちらかで解消しました.
    • inline のテストモジュールを sibling ファイル(src/<module>/tests.rs)に移す
    • まとまった submodule を切り出す(skills/frontmatter.rs)
  • 結合テストの分割: ルートファイルを残したまま,#[path = "neutral-generated-artifacts/x.rs"] mod x; の形で分割しました.テスト crate 名とテスト件数は変わっていません.

Codex レビューの指摘への対応

  • 問題: ExternalHookBundle::merge_hooks は,bundle の provider ファイルがあるかを確認する前に hooks["hooks"] を可変参照で取っていました.
    • "devin": {} の source に Claude 専用の --extra-hook を渡すと,hooks: null が挿入されていました.
    • その結果,sync-devin-config が既存の Devin hooks を null で上書きしていました.
  • 修正: HookFile::target を追加し,bundle のファイルを読めたときだけ参照を取るようにしました.
  • 回帰テスト: bundle_without_devin_hooks_keeps_existing_devin_hooks を追加しました.修正前のコードで失敗することを確認済みです.

挙動固定のために追加したテスト

  • hooks のコマンド再配置
  • hook メタデータの並び順
  • オブジェクトでない任意セクションの拒否
  • frontmatter の継続行の扱いと,キーより前の行の拒否
  • hooks inventory の出力(2 件)
  • 上記の Devin hooks の回帰テスト

確認結果(rebase 後の c64eb26)

確認項目 結果
cargo clippy --all-targets -- -D warnings OK
cargo test 全件 pass(lib 121 件,external_hook_bundles 14 件)
cargo deny check advisories ok, bans ok, licenses ok, sources ok
lefthook run pre-commit --all-files OK
ls_lint(引数なし) OK
CI 全チェック pass(all-green,rust-audit,test,lint,format,nix-lint,execpolicy,CodeQL,dependency-review)

🤖 Generated with Claude Code

@furedea-agent

furedea-agent Bot commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

追加の対応

  • Codex レビューの指摘(medium)を修正しました(4daf5eb). ExternalHookBundle::merge_hooks が bundle の provider ファイルの存在を確認する前に hooks["hooks"] を可変参照で取っていたため,"devin": {} の source と Claude 専用の --extra-hook を組み合わせると,hooks: null が挿入されていました.その結果,sync-devin-config が既存の Devin hooks を null で上書きしていました.ファイルの存在を確認してから参照を取るように直しました.
    • 回帰テスト bundle_without_devin_hooks_keeps_existing_devin_hooks を追加しました(generate と sync の後に既存の hooks が残ることを確認します).修正前のコードで失敗することを確認済みです.
  • CI の rust-audit の失敗はこの PR が原因ではありません. main でも RUSTSEC-2026-0382(rustls-webpki)と RUSTSEC-2026-0381(webpki-roots)で失敗しています.修正は fix(deps): update rustls-webpki and webpki-roots for security advisories #167 で別に出しています.fix(deps): update rustls-webpki and webpki-roots for security advisories #167 のマージ後に,このブランチを rebase します.

furedea added a commit that referenced this pull request Oct 21, 2026
…ies (#167)

## 概要

main の CI(rust-audit / cargo-deny)が次の 2 件の advisory で失敗しているため,ureq
経由で入っている 2 つの crate を修正版に更新します.変更は `Cargo.lock` だけです.

| advisory | crate | 更新前 | 更新後 |
| --- | --- | --- | --- |
| RUSTSEC-2026-0382 | rustls-webpki | 0.103.15 | 0.103.16 |
| RUSTSEC-2026-0381 | webpki-roots | 1.0.9 | 1.0.10 |

## 確認項目

- [x] `cargo update -p rustls-webpki -p webpki-roots` 以外の依存は変わっていない
- [x] `cargo deny check`: advisories ok, bans ok, licenses ok, sources
ok
- [x] `cargo test`: 全件 pass

## 詳細

flake は `cargoLock.lockFile = ./Cargo.lock`
を参照しており,固定ハッシュは持っていないため,flake 側の更新は不要です.

#166(numeric lint の適用)は,このPRのマージ後に rebase します.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: furedea <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
furedea and others added 6 commits October 21, 2026 13:52
Enable clippy all/pedantic with the nesting, argument-count, and cognitive
complexity thresholds from template-rust, and add the lefthook file-length
check.

Refs furedea/dotfiles#247

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Move branchy method bodies into module-level helpers, group the minted
token and issuer into MintedToken, and move inline test modules of
github_app and source into sibling files. Pin the hooks inventory output
with tests before restructuring it.

Refs furedea/dotfiles#247

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Group source, external hooks, and runtime root into GenerationContext and
skill destinations into SkillTarget so no function takes more than three
arguments. Extract nested blocks into helpers, split frontmatter parsing
and the hooks and skills tests into submodules to keep files under 500
lines, and pin hook relocation, metadata ordering, and frontmatter
parsing with tests before restructuring them.

Refs furedea/dotfiles#247

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Split the generated-artifact and external-hook-bundle suites into path
submodules to keep each file under 500 lines, and extract nested helpers.

Refs furedea/dotfiles#247

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Index the provider hooks key only after the bundle's hook file is known
to exist. Indexing first inserted a null hooks key into an empty Devin
section, and sync-devin-config then replaced the existing hooks with null.

Refs furedea/dotfiles#247

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Rust module directories are identifiers, so src/github_app violated the
kebab-case directory rule. Scope a snake_case directory rule to src and
re-merge the file rules through a YAML anchor, since a nested ls-lint
block replaces the root rules. Other directories, including tests/,
keep kebab-case. Matches template-rust.

Refs furedea/dotfiles#247

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@furedea-agent
furedea-agent Bot force-pushed the refactor/apply-numeric-lint branch from 5b6a6e0 to c64eb26 Compare October 21, 2026 04:57
@furedea
furedea merged commit d47f79e into main Oct 21, 2026
11 checks passed
@furedea
furedea deleted the refactor/apply-numeric-lint branch October 21, 2026 05:03
furedea added a commit to furedea/dotfiles that referenced this pull request Oct 21, 2026
## 概要

- `flake.lock` の `agent-harness` を main の最新(4057e01)に上げる.手元で `switch`
済み.
- 中身は furedea/agent-harness#166(数値 lint を入れるための,振る舞いを変えないリファクタリング)と
#167(`rustls-webpki` と `webpki-roots` の脆弱性の修正).

| 項目 | 変更前 | 変更後 |
|---|---|---|
| agent-harness | 60c871b(0.9.5) | 4057e01(main) |

## 受け入れ条件

- [x] 手元で `switch` できる
- [ ] CI が通る

<details>
<summary>参照元</summary>

- furedea/agent-harness#166,#167
- Refs #247
</details>

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: furedea <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
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