Repository navigation
refactor: apply template numeric lint rules - #12
Merged
Merged
Conversation
Adopt the numeric limits from template-rust and template-typescript: clippy cognitive_complexity, excessive_nesting, and allow_attributes_without_reason with the template thresholds, the lefthook file-length check, and oxlint complexity, max-depth, max-lines, and max-params for the embedded JXA. Move nested Display, parsing, and process-wait logic out of impl blocks into free functions, derive the mailbox depth from the parent path, pass integer ranges as one object, and split the JXA bridge into entry, lookup, and value files that are concatenated into the same single script. The helper files disable no-unused-vars because oxlint cannot see their callers in the other files. Pin the touched branches with tests first. Refs furedea/dotfiles#247 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rust module directories are identifiers, so allow snake_case directory names under src while keeping kebab-case elsewhere. A nested ls-lint block replaces the root rules, so the file rules are shared through a YAML anchor, matching template-rust. Map the embedded JXA sources to src/osascript.rs for the agent verification hook, because their tests run through the Rust harness. Refs furedea/dotfiles#247 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
template-rust / template-typescript の数値系 lint ルールを導入し,既存違反をすべて挙動を変えないリファクタリングで解消しました.埋め込み JXA(
src/mail_bridge.js)にも TypeScript テンプレートの数値ルールを適用しています.あわせて,承認済みの追加変更が 2 つあります.
src配下だけディレクトリ名に snake_case を許可しました(Rust のモジュールディレクトリ用).Refs furedea/dotfiles#247
違反件数
clippy::excessive_nesting(threshold 2)cognitive_complexity/too_many_arguments/allow_attributes_without_reasonmax-depth(2)max-params(3)max-lines(500)complexity(10)受け入れ条件
Cargo.toml[lints.clippy],clippy.toml,.oxlintrc.json)と lefthook(file-length)に入れた#[allow]やoxlint-disableは使っていない(例外 1 件は下記の override で,ユーザー承認済み)src配下だけ snake_case のディレクトリ名を許可し,tests/などでは kebab-case を維持したsrc/mail_bridge*の変更で,検証フックがsrc/osascript.rsの Rust テストを選ぶようにした確認したコマンド
cargo fmt --checkcargo clippy --all-targets -- -D warningscargo test --locked(JXA harness を含む全テスト)cargo build --lockedpnpm run check(oxfmt,oxlint,tsc)lefthook run pre-commit --all-filesls_lint(引数なし.下記のプローブでも確認)詳細
数値ルールの設定
Cargo.toml:allow_attributes_without_reason,cognitive_complexity,excessive_nestingを warn に設定clippy.toml:テンプレートと同じしきい値(too-many-arguments 3,excessive-nesting 2,cognitive-complexity 15)lefthook.yml:テンプレートのfile-length(*.rsは 500 行以下)を追加.oxlintrc.json:complexity10,max-depth2,max-lines500,max-params3 を追加Rust
nesting threshold 2 では,impl 内メソッドの match arm や if のブロックがそれだけで 3 段になります.そのため処理を自由関数へ移しました.
src/bridge.rs,src/application.rs:Display::fmtの本体をwrite_bridge_errorとwrite_application_errorに移動src/cli.rs:BoundedText::from_strの検証をvalidate_text_lengthに移動src/osascript.rs:executeの終了コード判定をsuccessful_stdoutに,run_processの待機ループをwait_for_exitに移動.タイムアウトや失敗時の後始末(kill,wait,reader の回収)は元と同じですJXA
max-depth:mailboxPath内の try をreadableParentに抽出max-params:appendMailboxesのdepthは常にparents.lengthと一致するので引数から外しました.requireIntegerの最小値と最大値はIntegerRangeオブジェクトで受け取りますmax-lines:mail_bridge.js(エントリとハンドラ,282 行),mail_bridge_lookup.js(アカウント,メールボックス,メッセージの解決とパス,213 行),mail_bridge_values.js(入力検証,値の整形,エラー,170 行)に分割しました.osascript.rsでconcat!(include_str!(..))して 1 本のスクリプトとして渡すので,実行時の成果物は従来どおり 1 つで,トランスパイルもありません(ADR-0004 の範囲内).tsconfig.jsonとpackage.jsonのスクリプトに新しいファイルを追加しましたlint 例外(ユーザー承認済み)
.oxlintrc.jsonの override で,mail_bridge_lookup.jsとmail_bridge_values.jsだけeslint/no-unused-varsを off にしています.JXA はモジュール機構のない単一スクリプトで,oxlint は/* exported */を解釈しません.そのため分割すると,他のファイルから呼ぶ関数が未使用と誤検知されます.tsc と他の lint ルールは全ファイルに適用されたままです.ls-lint:
src配下の snake_case ディレクトリls-lint v2 では,
src:のようなネストしたブロックはルートの規則を継承せず,置き換えます.そのため template-rust と同じく,ルートのファイル規則を YAML アンカー(<<: &files)にまとめ,srcブロックで<<: *filesとしてマージしたうえで,.dir: regex:[a-z0-9]+(_[a-z0-9]+)*を指定しました.このリポジトリのルートのファイル規則は.yamlと.*です(README,Cargo.toml などは従来どおり ignore で除外しています).引数なしの
ls_lintに,一時的なプローブを置いて確認しました(確認後に削除済み).src/good_dir,src/good_dir/nested_dirsrc/bad-dir.dirの snake_case 規則で失敗tests/bad_dirsrc/BadFile.rs.*規則で失敗src/good_dir/Bad-Name.yaml.yaml規則で失敗(pnpm-workspace.yamlは通る)検証フックとテストの対応付け
.agents/hooks/rules/related_test_extensions.jsonでsrc/mail_bridge*(.d.tsを含む)をsrc/osascript.rsに対応付けました.JXA のテストは Rust の harness からcargo testで実行しているためです.フックの選択ロジックで確認した結果は次のとおりです..d.tscargo test osascriptsrc/osascript.rscargo testの全件package.jsonまたはtsconfig.jsonと JXA を同時に変更package.jsonやtsconfig.jsonを変更すると,フックは JS テストの全件実行を必須にし,他言語のテストへの委譲を無視します.この PR は両方のファイルを変更しているので,このセッションでは Stop hook が「test command could not be determined」のままです.これはフック側の仕様によるもので,テストの失敗ではありません.追加したテスト(リファクタリング前に挙動を固定)
tests/bridge.rs:BridgeErrorの表示文言tests/application.rs:JSON でない応答と,オブジェクトでない envelope の表示文言tests/cli.rs:空のクエリと上限超過クエリのエラー文言src/osascript.rs(JXA harness):container が読めないときのメールボックスパス,ネスト 32 段の受理と 33 段の拒否,limitの範囲外と非整数の拒否🤖 Generated with Claude Code