Repository navigation
refactor: enforce template-python numeric lint limits - #233
Merged
Merged
Conversation
Refs #227 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Refs #227 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Refs #227 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Refs #227 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Refs #227 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Refs #227 Co-Authored-By: Claude Opus 5.5 <[email protected]>
3 tasks
furedea
added a commit
that referenced
this pull request
Nov 10, 2026
## 概要 dotfiles の ruff 設定を template-python に揃える (Refs furedea/agent-config#74,cfg-align の dotfiles 行). ## 設定の変更 (`pyproject.toml`) - `select` をテンプレートの順序にそろえ,`DOC` を追加 (違反 0).`CPY` は template-python 側でも削除済みのため入れない. - `ignore` をテンプレートの一覧に置換し,下表の 18 件を削除. - `PLR0917` は tests 限定の ignore からグローバルの `ignore` に移動 (ユーザー判断).理由はコメントで明記. - プロジェクト固有の ignore は無い. ## 削除した ignore の元の理由 元の理由は `git log -S` で追跡.18 件はすべて 8428059 (2026-05,`build(python): bootstrap uv project for hook and script tests`) で,当時のスキル用スクリプトを温存するコメント付きで追加された.faa537f (#2) でスクリプトが移設されたときにコメントが落ち,de295d1 (#52) で理由なしで再追加された.保護対象のスクリプト (`agents/skills/**/scripts/*.py`,`run_audit.py` など) は faa537f と 83d1a89 (#98) で削除済みで,現在の Python は `github/`,`herdr/`,`zsh/`,`tests/` のみ. 削除後,全 18 規則を有効にして全体を検査した結果,違反が出たのは I001,E501,ARG001 のみで,下記のとおり修正済み. | 規則 | 検査内容 | 元の理由 (8428059 のコメント) | 現在は当てはまらない理由 | | -------------- | ------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ARG001 | 未使用の関数引数 | "Patch schema keeps current_description for compatibility" | 対象の `apply_patches.py` は削除済み.違反はテストの 1 件のみで,`usefixtures` に移して修正. | | B007 | 未使用のループ変数 | "os.walk tuple names document positional contents in existing code" | `os.walk` を使うコードは存在しない (grep で 0). | | C401 | `set(generator)` を内包表記へ | "Existing aggregation code favors explicit generator layout" | 対象の集計コード (`collect_transcripts.py` など) は削除済み.違反 0. | | DTZ005 | tz 無しの `datetime.now()` | "Timestamped local workspace names intentionally use local time" | ローカル時刻の作業ディレクトリ名を作る `run_audit.py` は削除済み.`datetime.now()` の使用 0. | | E402 | import がファイル先頭にない | "run_audit adjusts sys.path before importing sibling scripts" | `run_audit.py` は削除済み.`sys.path` を操作するコードは存在しない (grep で 0). | | E501 | 行が 119 桁超 | "Embedded HTML/JS templates intentionally preserve long source strings" | `generate_report.py` の HTML/JS テンプレートは削除済み.残りの 6 行はテスト内の fake スクリプトで,分割して修正. | | F541 | プレースホルダーの無い f-string | "Existing report/changelog writes include harmless f-string literals" | レポート出力コードは削除済み.違反 0. | | FURB110 | `x if x else y` を `x or y` へ | "Existing JSON output code keeps explicit empty-list fallback branches" | 対象の JSON 出力コードは削除済み.違反 0. | | FURB122 | ループ内の `write` を `writelines` へ | "Existing changelog writes favor straightforward loops" | changelog を書くコードは削除済み.違反 0. | | FURB162 | 末尾 `Z` の手動置換 | "Existing timestamp parser normalizes trailing Z explicitly" | transcript のタイムスタンプパーサーは削除済み.違反 0. | | FURB171 | 1 要素のタプルでの `in` | "Existing message-type checks use tuple style consistently" | message-type 判定のコードは削除済み.違反 0. | | I001 | import の並び順 | "Keep script import blocks stable while sys.path bootstrapping is present" | `sys.path` を操作するスクリプトが無くなり,理由が消えた.15 ファイルを `ruff --fix` で整列. | | PERF401 | ループでの `append` を内包表記へ | "Existing batching code favors stepwise mutation for readability" | バッチ処理コードは削除済み.違反 0. | | PTH | `os.path` 等を `pathlib` へ | "Legacy scripts use os.path; Path migration is a separate refactor" | `os.path` を使うレガシースクリプトは削除済み.現在のコードは `pathlib` で,違反 0. | | PLW2901 | ループ変数の上書き | "Existing JSONL parser reuses line after stripping whitespace" | JSONL パーサーは削除済み.違反 0. | | RUF005 | リスト連結を展開構文へ | "Existing path reconstruction code is clearer with list concatenation" | 対象のパス再構築コードは削除済み.違反 0. | | UP015 | 冗長な `open` のモード指定 | "Explicit read/write modes are kept for CLI-script clarity" | CLI スクリプトは削除済み.違反 0. | | UP017 | `timezone.utc` を `datetime.UTC` へ | "Existing code imports timezone explicitly" | `timezone` を import するコードは存在しない (grep で 0). | | PLR0917 (移動) | 位置引数の数 (`max-args` に従う) | dcb0709 (#233): "In ruff 0.16.3, `PLR0917` (positional args) is stable and follows `max-args`, so pytest fixtures would add 83 test-only violations." | 理由 (pytest のフィクスチャ) は今も有効なので,無視は維持.位置引数の数は全引数数以下で,PLR0913 (max-args = 3) が既に上限を課すため,個別の ignore はグローバルに移動して統一. | 元の理由がまだ成り立つ項目は無かったため,復元した ignore は無い. ## コード修正 (別コミット) | 規則 | 修正前 | 修正後 | 対応 | | ------ | ----------------------------------------------- | ------ | ------------------------------------------------------------------------------------ | | I001 | 15 ファイル | 0 | `ruff --fix --select I001` | | E501 | 6 行 (テスト内の fake スクリプトと文字列) | 0 | 変数の導入・括弧での分割.抑制なし | | ARG001 | 1 (`tests/github/test_repo_cli.py` の `remote`) | 0 | 副作用目的のフィクスチャを `@pytest.mark.usefixtures("remote")` に移し,引数から削除 | 非自明な修正の設計上の理由:`remote` は fake `gh` のリモート環境を用意する副作用のためだけに要求されていたので,usefixtures に移すのが pytest の意図に沿う (未使用引数を `_` で隠すより正しい). ## 確認 - `ruff check` / `ruff format --check` 通過,`pytest` 164 passed,`ty` 通過 (pre-commit) - ruff の `select` はテンプレートと同じ並び.`ignore` はテンプレートの一覧に `PLR0917` (理由コメント付き) を加えたもの 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: furedea <[email protected]> Co-authored-by: Claude Sonnet 5.5 <[email protected]>
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.
Summary
max-args = 3,max-nested-blocks = 2(PLR1702, preview-only viaexplicit-preview-rules),C901withmax-complexity = 10, and drop thePLR0911/PLR0912/PLR0913/PGH004ignores.file-lengthcheck (500 lines) for hand-written code:py,sh,bash,bats,zsh,lua,js,ts. Nix modules, data, and docs are excluded.audit_log.Refusal,check_selection.Selection,session_gate.VerificationRun). Nonoqawas added.Decisions to review
tests/**ignoresPLR0917in addition to the template'sPLR0913. In ruff 0.16.3,PLR0917(positional args) is stable and followsmax-args, so pytest fixtures would add 83 test-only violations. The template is still on ruff 0.15 (wherePLR0917is preview) and has not hit this yet.file-lengthbecausenix/home/default.nixis 727 lines. Splitting it belongs in a separate change.file-lengthis enforced locally only. Ruff limits are enforced in CI through the existingruff checkstep.Notable API changes (internal)
audit_log.blocked/escalatednow take a singleRefusal. The unusedvalue/reasonarguments are gone; they were never logged.session_store.register(..., resuming=True)is nowsession_store.resume(...).lint_engine.diagnosticsnow takes pre-filtered targets fromsupported_targets, and the unusedreadonlyparameter is removed.Tests
Before splitting, I added characterization tests and confirmed they pass on the original code:
test_forbidden_command,test_command_policy,test_guard_git,test_guard_file,test_git_safetyVerification
uv run --frozen pytest -m 'not integration': 1440 passedlefthook run pre-commit --all-files: all commands pass, includingfile-lengthbats tests/agents/bootstrap_server.bats tests/moshi/update_moshi_hook.bats: passbats tests/esa/zsh.bats: hangs at test 11 in the local sandbox. It hangs identically with the originalzsh/esa.py, so the cause is the environment, not this change. CI should confirm.Closes #227
🤖 Generated with Claude Code