Repository navigation
feat(lint): migrate python-style rules to ast-grep and model rules - #192
Conversation
Add nine ast-grep rules and seven advisory jev-lint rules for python-style, and drop the prose that ruff or the new rules already judge. Refs #74 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Review summary (read-only) No blocking findings (no P0 or P1). Three inline comments:
Checked with no issues found: the other ast-grep rules and their rule-tests, the other jev-lint matchers, the narrower 🤖 Generated with Claude Code |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ee9faa22fe
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…in python rules Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
@codex review |
Review summaryNo blocking findings (0 × P0, 0 × P1). The new ast-grep findings are advisory: Inline findings
Checked and found OK: the Not verified locally: |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ba9ff6d5c8
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…ses and msg keyword Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
@codex review |
Review summaryNo blocking findings (0 × P0/P1). These are new ast-grep rules and jev-lint model rules. They are advisory: Inline findings:
Note: I couldn't run |
…wer false positives Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f900d794e2
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
レビュー概要正しさ,セキュリティ,テストの不足を見た.merge を止める指摘(P0/P1)は無い.
補足:
🤖 Generated with Claude Code |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d0f019d94b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…mark; pin model-rule subjects Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…two to jev-lint py_async_test_anyio_marker is dropped: pytest 9.0.3 fails an async test that no plugin runs. py_pydantic_validate_json and py_plain_class_slots become advisory model rules. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
@codex review |
|
Review summary (read-only) Blocking (P0/P1): none.
Other checks:
🤖 Generated with Claude Code |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 63f22c4ea2
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 63f22c4ea2
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Following the class hierarchy across classes is not reliable in ast-grep. The json rule now treats loader conversion options as not equivalent to model_validate_json. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
@codex review |
Review summary (read-only)No blocking findings. Reviewed:
What I checked:
Minor note, not filed as a finding: pydantic applies class keywords after I could not run |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e7633f6e8e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e7633f6e8e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Following a named config constant is data flow that ast-grep cannot do reliably. Add submodule-import cases to the pytest-asyncio rule, which already reports them. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
@codex review |
Review summaryRead-only review of the new ast-grep rules, jev-lint model rules, skill text changes and tests.
Nothing else blocking. The other rule matchers agree with the subject counts in Blocking findings (P0/P1): 1 |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f816b76b84
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Refs #74 Refs #196 ## 概要 ADR-0021 に「Which rules ast-grep may block」の節を追加し,blocking な ast-grep 規則に求める基準を記録した. - blocking な ast-grep 規則は,1 つの構文要素を局所的に,信頼できる形で判定しなければならない.次のどれかが必要な規則は,言語自身の linter / compiler / test runner(あれば),なければ jev-lint に任せる. 1. ファイル外の情報(設定,`conftest.py`,他のモジュール) 2. データの流れや実行の順番(代入,スコープ,クラス階層) 3. 文法や式を正規表現で解析すること(`cfg(...)`,文字列の中身) 4. 同じ意味の書き方が多いこと(YAML の引用符・flow / block 形式,import の別名) - 根拠として,#192〜#195 のマージ済み PR 本文の「ast-grep から外した規則と理由」の表から,指摘 8 件以上の 12 規則を表にした(規則,指摘数,型,行き先). - `agents/hooks/lint/sgconfig.yml` の先頭に,この節への 1 行の案内をコメントで追加した. - `tests/test_workflow_skill_layout.py`: 追跡されていない `agents/skills/.claude/` が skill として読まれ,環境によって失敗する問題を直した.`.` で始まる名前を `SKILL_NAMES` から除外する(`skill_names()`,先にテストを追加して失敗を確認). ## 補足 - #194 は作成時点で未マージのため,ADR の #194 の 3 行は暫定と明記した(レビュー指摘). - 依頼文では「外した規則は 11〜34 件」とあったが,PR 本文の表には 1〜8 件の規則もある(#193 の Rust など).表には 8 件以上のものだけを載せ,それ未満は「同じ PR 本文に載っており,同じ型に当てはまる」と ADR に書いた.ブロックのまま残った規則は 3 件以下(#194 の Bash / GitHub Actions は 3〜7 件で,見逃しは #196 に送った)と書いている. - 指摘数は各 PR 本文の記載値をそのまま使った(再集計していない). ## 検証 - `uv run pytest tests/test_workflow_skill_layout.py`: 61 件成功(新規テストは,実装前に `NameError` で失敗することを確認). - pre-commit(ruff,ty,shellcheck,commitlint ほか)通過.`dprint fmt` 済み. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: furedea <132188853+furedea@users.noreply.github.com> Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
## 概要 #196 に溜まった指摘を,main に残っている blocking(`severity: error`)の ast-grep 規則に絞って整理し,規則内の局所的な 1 構文の確認で直せるものを直した.#74 の一部. 分類は次のとおり. - **a**:blocking 規則の見逃し・誤検出(規則が main に残っている) - **b**:jev-lint model rule の指摘(保留中の検証用に残す.変更しない) - **c**:obsolete(規則が削除・置換済み) - **d**:hook・文章・インフラ ADR-0021 に入れる基準(#214)は未マージのため,指示された基準をそのまま適用した.局所的な 1 構文(固定名,文字列の接頭辞,ノード種別 1 つの追加)なら規則を直す.ファイル外の情報,データフロー・スコープ,入れ子の文法の正規表現,同義の書き方を追い続ける修正が必要なものは,規則を継ぎ足さない. ## a.blocking 規則(fixture を先に足して修正) | 項目 | 分類 | 対応 | | --------------------------------------------------------------------------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `go_no_generated_mocks`:`// Code generated by ...` ヘッダーだけの生成 mock | a 修正 | ヘッダーの接頭辞(MockGen / mockery / counterfeiter / moq / minimock)を検出 | | `go_no_context_in_struct`:`*context.Context` のフィールド | a 修正 | `pointer_type` を 1 種類追加 | | `go_use_slog`:receiver・名前付き戻り値による `log` のシャドー | a 修正 | 引数と同じ判定を receiver・result にも適用 | | `rs_no_mocking_library`:`automock` クレート,`pub use`,`use {mockall::automock};` | a 修正 | クレート一覧と `use` の接頭辞を拡張 | | `rs_no_mocking_library`:`cfg_attr` 分岐が入れ子の属性を正規表現で読む(#196 最後のコメント) | a 修正 | 正規表現をやめ,`cfg_attr` の引数トークン(カンマの直後の識別子)をノードで判定 | | `bash_readonly_constant_name`:`declare -r` を検査しない | a 修正 | スクリプト直下の `declare -r` / `typeset -r` と,関数内の `declare -gr` を追加 | | `bash_readonly_constant_name`:関数内の `readonly` を一律に除外 | a Limits | 既存の `local` を固定するだけの `readonly` と区別するにはスコープ解析が要るため,除外のまま規則の Scope に記録した(レビュー指摘で一度検査に変えたが戻した) | | `py_pydantic_base_model_only_in_frozen_base`:`pydantic.v1` 経由の回避 | a 修正 | `pydantic.v1` の素の書き方を追加 | | `go_use_slog`:関数内のローカル変数による `log` のシャドー | a Limits | スコープ解析が要る.規則の本体は精度が高く,demote すると `log.Printf` を止められなくなるため,blocking のまま規則の Limits に記録した | | `go_iota_enum_typed`:`iota + 1` などの式 | a Limits | `1 << (10 * iota)` と `iota + 1` は型なし定数の標準的な書き方で,構文だけでは enum と区別できない.既存の valid fixture のとおり対象外のまま,理由を規則に記録した | | `rs_no_follow_links`:import 別名,途中で別の型に変換するチェーン | a Limits | 別名はバインド解析が要る.変換するチェーンは該当する API を確認できていない.規則の Limits に記録した | | `py_no_pytest_asyncio`:別名 `pytest` 経由 | a Limits | バインド解析が要る.規則の Limits に記録した | | `gha_job_timeout_minutes`:`jobs` 自体が flow mapping | a Limits | 実在の workflow では使われない書き方.規則の Scope に記録した | | `gha_workflow_permissions_deny_all`:ルート全体が flow mapping | a Limits | 同上 | | `gha_pinned_uses_version_comment`:`action.yml` 内の tag 参照 | c | 規則は `action.yml` を対象に含んでいる.tag 参照は対象外と Scope に書いてある設計どおり | | `go_context_param_named_ctx` / `go_no_context_in_struct`:import path・エイリアスの確認 | c | 規則が標準 `context` を別名なしで import したファイルに限定済み | | `go_no_generated_mocks`:`//go:generate` 経由の mock | c | 規則が検出済み | 「a Limits」は,構文だけでは判定できない見逃しの端のケースで,規則は demote せず,規則ファイルの `Limits:`(または `Scope:`)に記録した.精度の高い規則は,見逃しを記録して残す.誤検出が繰り返し出る規則だけを demote する.この方針は ADR-0021 の「Which rules ast-grep may block」に 1 行足した. ## c.obsolete(規則が削除・置換済み) main に該当の規則が無いため,対応不要. - TypeScript:`ts_no_unvalidated_json_cast`,`ts_catch_rethrow_requires_cause`,`ts_no_other_test_framework`,`ts_no_vague_name`,`ts_no_home_dir_in_tests` と各 `tsx_` 版(oxlint・jev-lint へ移行) - Python:`py_async_test_anyio_marker`(削除),`py_pydantic_validate_json`,`py_plain_class_slots`(jev-lint へ降格),`py_frozen_base_model_config`,`py_frozen_base_model_no_override`,`py_definition_order`,`string-literal-is-named-constant` の `parent:` の件 - Go:`go_sealed_interface_sumtype_decl`,`go_error_no_capitalized_message` - Rust:`rs_unit_test_in_test_module`(clippy へ置換),`rs_no_path_from_format`(jev-lint へ降格),`rs_fs_call_needs_context`,`rs_no_get_prefix` - Bash / Actions:`gha_workflow_concurrency`,`gha_workflow_default_shell`,`bash_strict_mode_header`(jev-lint へ降格) ## b.jev-lint model rule の指摘(変更しない) 保留中の fixtures・eval・しきい値の当てはめで扱う.#196 のコメントに記録済みで,この PR では触れない. - `no-exposed-mutable-collection`,`no-comment-restating-code`,`no-reaching-through-collaborators`,`construction-separate-from-execution`,`function-single-purpose`(#191,4 言語) - `error-handled-once`(#190),`fixture-justified`,`frozen-model-subclass-keeps-locked-settings`,`json-parse-uses-model-validate-json`(#192) - Rust の advisory 規則:`conversion-and-query-names-follow-rust-convention`,`serde-types-follow-config-conventions`,`public-types-protect-invariants`,`domain-states-are-enums`,`paths-are-joined-not-formatted`(#193) - Bash / Actions の advisory 規則(#194),TypeScript の advisory 規則(#195) - `test_main_is_thin_selects_func_main_of_package_main` が `command-query-naming` に指摘される件(誤検出と見ている.model rule の判定の話) ## d.hook・文章・インフラ | 項目 | 分類 | 対応 | |---|---|---| | worktree の未追跡 `agents/skills/.claude/` を skill と読み,`tests/test_workflow_skill_layout.py` が失敗する | d 解決済み | main に同じ修正が入っていた(#216 の rebase で採用) | | Stop の `SUBJECT_CAP`(20)で判定が漏れないようにする | d 解決済み | 現在は 250 で,実測の上限を下回らないことをテストが保証している | | 後段の review が失敗すると,同じ指摘で毎ターン Stop を block する | d 修正 | 完了した前段の結果をレシートの `resume` に保存し,失敗した tier だけを再実行する.通知済みの件数(`shown`)も保存し,同じ指摘では二度 block しない | | 後段の review の失敗理由が捨てられ,`incomplete` としか出ない.`skipped_files=1` が実数でない | d 修正 | `Judgement.failure_reason` を結果の行に出し,`skipped_files` は失敗した review のファイル数にした | | 2 tier の review の順序(調整済み committed,調整済み uncommitted,未調整 committed,未調整 uncommitted)のテストが無い | d 修正 | `test_model_rules_resume.py` に順序のテストを追加 | | `scripts/bootstrap_server.sh` が ast-grep を入れない | d 修正 | ast-grep 0.42.1 を sha256 付きで固定し,dprint と同じ zip の経路で入れる(`install_zip_tool`).bats の fixture,Renovate の確認,README を更新 | | `.bats` を ast-grep で Bash として読めるか | d 対応しない | `languageGlobs`(`bash: ["*.bats"]`)で読めることは確認したが,Bash の規則は `.bats` に有効化しない.`@test` ブロックは Bash の文法ではなく,読めても `readonly` や関数名の規則が意図しない形で当たる.hook の `EXTENSIONS` と整形の対象も広がる | | `severity: error` を hook の block 判定に結びつける | d 範囲外 | #203 の範囲 | | Rust `tooling.md` の package-level guard,Go の `t.Parallel()` の文章 | d 対応しない | テンプレートの linter が既に覆っているため,文章は戻さない | | `types.md` の `to_owned()` / `String::from`,`package_design.md` の `pub`,`types.md` の exhaustive match,`errors.md` の `# Panics` の文章 | d 対応しない | 同上(テンプレートの linter が覆う分は戻さない) | ## 検証 - ast-grep の規則テスト:28 件通過,bats:81 件通過(ast-grep の固定を追加) - `uv run pytest`:5198 件通過,4 件失敗.失敗はいずれも model rule の subject 選択テスト(`test_main_is_thin_selects_func_main_of_package_main` など)で,この PR を外した main でも同じく失敗する(この環境での既存の失敗.CI の `test` job は通る) - `ruff check` / `ruff format --check` / `ty`:通過 Refs #74, #196 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: furedea <132188853+furedea@users.noreply.github.com> Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
…258) ## 概要 #196 の Python 項目(#192 の後続,`py_*` 規則,Python の model rule,#191 の Python 部分)を origin/main で確かめた.ast-grep の項目は #192・#216・#240 で対応済みか obsolete だった.残っていた Python の model rule の selector 3 件を広げた(#196 の方針どおり matcher は広く取り,判定は criteria に任せる).どの規則も advisory のままで,昇格も文章の削除もしていない(ADR-0027). Refs #196 ## 変更 - `no-reaching-through-collaborators`:呼び出しで終わらないプロパティ参照の連鎖(`return order.customer.address.city`)も選ぶ.selector を `$A.$B.$C.$D($$$)` から `$A.$B.$C.$D` にした(呼び出しの連鎖も含む). - `no-exposed-mutable-collection`:公開名のフィールドをそのまま返す関数(`return self.items`)も選ぶ.`return len(self.items)` のような計算結果は選ばない. - `no-comment-restating-code`:関数の直前(デコレータの上を含む)にある,tool directive でないコメントも選ぶ.規則は `axis: file` なのでモデルにはファイル全体が渡り,直前のコメントも見える. - 3 規則の fixtures に新しい形の bad(とコメント規則の clean 1 件)を足し,`expect.yml` に label を足した.既存の行番号は動かしていない. - `tests/test_python_model_rules.py`:3 件の selector テストを追加(Red は 3 件とも subject 0 で確認). - `tests/test_agents_md_model_rules.py`:Python の共通サンプルで `label`(`return self.text`)が新たに選ばれるので期待値を 2 にした. ## 項目ごとの状態 | 項目 | 状態 | 根拠 | | -------------------------------------------------------------------------------------------- | ------------------ | ----------------------------------------------------------------------------------------------------------------- | | `string-literal-is-named-constant`:`parent:` が ast-grep のキーでない | 対応済み | 現在の規則に `parent:` は無い(#216 で obsolete と整理) | | `py_definition_order`:`ColorMixin[T]` を Enum 扱い | obsolete | 規則は #192 で削除 | | `py_async_test_anyio_marker`(部分一致,fixture 経由,別名 receiver,`anyio_mode = "auto"`) | obsolete | 規則は #192 で削除(ADR-0021) | | `py_plain_class_slots`(アンパック代入,`__dict__`,`class User()` / `(object)`) | obsolete | jev-lint `plain-class-defines-slots` へ降格(#192) | | `py_pydantic_validate_json`(初期化,`json` の束縛,複数名 import の別名) | obsolete | jev-lint `json-parse-uses-model-validate-json` へ降格(#192) | | `py_frozen_base_model_config`:`model_config` の再代入 | obsolete | 規則は削除,jev-lint `frozen-base-model-sets-all-settings` へ(#192) | | `py_frozen_base_model_no_override`:`ConfigDict(**{...})` | obsolete | 規則は削除,jev-lint `frozen-model-subclass-keeps-locked-settings` へ(#192) | | `py_pydantic_base_model_only_in_frozen_base`:`pydantic.v1` | 対応済み | #216(`from pydantic.v1 import BaseModel` と `pydantic.v1.BaseModel` を invalid に追加済み.別名は規則の Limits) | | `py_no_pytest_asyncio`:別名 `pytest` 経由のマーカー | 対応済み(Limits) | #216 で規則の `Limits:` に記録(バインド解析が要る.ADR-0021 の方針で demote しない) | | `py_dataclass_slots` | 対応済み | #192 本文の後続項目(`cached_property` の別名)は #192 内で修正済み.#196 に未解決の個別項目は無い | | `fixture-justified`:基準の衝突 | 対応済み | #240 | | `json-parse-uses-model-validate-json`:callee で照合 | 対応済み | #240 | | `frozen-model-subclass-keeps-locked-settings`:別ファイルの基底 | 対応済み(Limits) | #240(`located` のまま,別ファイルの中間クラスは Limits) | | `no-comment-restating-code`:Python の docstring | 対応済み | 現在の selector に docstring の分岐がある(`tests/test_agents_md_model_rules.py` の `documented`) | | `no-comment-restating-code`:関数直前のコメント(Python 分) | 修正 | この PR | | `no-exposed-mutable-collection`:Python 公開名のフィールド | 修正 | この PR | | `no-reaching-through-collaborators`:プロパティ参照の連鎖(Python 分) | 修正 | この PR | | ローカルで失敗していた `test_python_style_model_rules_select_the_subjects_they_ask_about` | 対応済み | origin/main ではローカルでも通る(rebase 後に確認) | ## baseline の再取得と cutoff matcher を変えた 3 suite の baseline は,ユーザーが `jev-lint eval --accept` で取り直した(2026-11-19T12:18Z,3 passes).cutoff と根拠のコメントをその値に合わせた(a70d16d5).問い(ask / criteria)はその後変えていない. | 規則 | cutoff | 結果(3 passes の平均) | | --- | --- | --- | | `no-reaching-through-collaborators` | 0.79(据え置き) | 呼び出しで終わる違反は最低 0.87,clean は最高 0.72.プロパティ連鎖の bad(subjects.py:48)は 0.68 で FN | | `no-exposed-mutable-collection` | 0.5(据え置き) | 公開フィールドの bad(subjects.py:95)は 0.96 で検出.従来からの FP(CsvRow,subjects.py:80)は 0.94 | | `no-comment-restating-code` | 0.59 → 0.62 | clean は最高 0.37(公開 docstring),関数内の違反は最低 0.87.関数直前コメントの bad(subjects.py:61)は 0.11 で FN.古くなった `inconclusive:` を削除 | ## Limits - `no-reaching-through-collaborators`:呼び出しで終わらないプロパティ連鎖は選ぶようになったが,fixture では 0.68(clean の 0.67 と 0.72 の間)で,どの cutoff でも分離しない.今は見逃す(FN). - `no-comment-restating-code`:関数直前のコメントは選ぶようになったが,fixture の言い換えコメントは 0.11 で見逃す(FN).また `follows` は直前の兄弟コメントを何でも選ぶので,前の文の行末コメント(`TIMEOUT = 5 # seconds`),空行を挟んだ区切りコメント,複数行コメントの最終行だけを directive 判定する場合にも subject が増える(余分な問い合わせ.2 回目のレビュー指摘). - `no-exposed-mutable-collection`:公開フィールドの getter(`return self.name`)をすべて選ぶので subject が増える(#196 の方針で matcher は広く取る).`return (self.items)` のように括弧で包む書き方は選ばない(見逃し.2 回目のレビュー指摘).CsvRow の FP(0.94)は従来どおり残る. ## レビュー対応 - 1 回目:`no-comment-restating-code` の ask を「in this function, or just above it」に合わせた.関数直前コメントの bad fixture を非公開 helper にした(7ab1c139).baseline は上のとおり再取得した. - 2 回目:指摘 3 件(行末・区切りコメントの選択,公開 getter の広さ,括弧付きの return)は,レビュー 1 回分の方針により直さず Limits に記録した.どの thread も返信して resolve 済み. ## テスト - `uv run pytest`:replay を含む model rule のテストが通過. - `jev-lint eval --replay`:74 suite すべて通過. - ruff,ty(pre-commit)は通過. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: furedea <132188853+furedea@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Refs #74(Python レーン)
Refs #196
計画: #74 (comment)
概要
最終方針(ユーザー決定): 静的な ast-grep 規則は linter の error と同じく止める(
severity: error).残すのはpy_no_nonlocal,py_no_pytest_asyncio,py_async_test_anyio_marker(anyioを完全一致で判定),py_no_unittest,py_no_unittest_mock,py_xfail_requires_strict,py_mocker_patch_autospec,py_no_staticmethod,py_dataclass_slots,py_plain_class_slotsと新規 4 規則.py_logging_dict_message,py_loop_variable_descriptive,py_definition_order,py_frozen_config_completeは規則と例のテストと文章を削除した.py_no_pytest_asyncioはpytest.mark.asyncioとpytest_asyncioの import だけに絞った.まれな例外は,レビュー済みの suppression コメントで通す.python-styleskill の文章規則を 1 規則ずつ棚卸しし,最も安い判定手段へ移した(ADR-0020,ADR-0021).rule-testsを各規則に valid / invalid 各 3 件以上付けた.model-rules/python/)を 7 件追加した.文章は ADR-0021 に従い残す.fixtures,eval の当てはめ,baseline は延期(ユーザー指示).furedea/template-*からだけ作る.template のmainで有効な linter 規則が完全に覆う文章は削除し,規則 ID を表に書く.重複する ast-grep 規則py_prefer_strenum(UP042と重複)は規則とテストごと削除した.覆われない部分(例外,理由,直し方)は残す.共有ファイルの変更は
tests/test_model_rule_files.pyだけ(Python の比較をRULE_IDSの 3 件に限る変更と,新しい 7 件の subject 数を固定するテストtest_python_style_model_rules_select_the_subjects_they_ask_aboutの追加).test_python_rules_select_the_functions_they_ask_aboutが Python の規則 3 件の subject 数を完全一致で比較していたため,新しい Python 規則が別の subject(fixture,import,値オブジェクトなど)を選ぶと失敗する.比較を既存のRULE_IDSの 3 件に限った.他レーンが同じ関数を編集した場合は,マージ時に同じ方針で解消する.文章と規則の対応表
「元の場所」は
agents/skills/python-style/からの相対パス.ast-grep の実装はagents/hooks/lint/rules/python/,例のテストはagents/hooks/lint/rule-tests/,jev-lint の実装はagents/hooks/lint/model-rules/python/<id>/rule.yml.py_no_nonlocalglobal,nonlocalglobalは既存 linter(ruffPLW0603)py_no_nonlocal.ymlnonlocalは本規則,globalは template-python の ruffPLW0603が置換)UP006/UP035typing.Tuple,typing.List,typing.DictUP006,UP035.template-python はUPを選択済み)py_logging_dict_message(削除)/py_no_structlog_loguru(新規)loggingとextraを使う方針に変え,structlog と loguru の import を禁止する静的規則(ast-grep,error)を追加py_no_structlog_loguru.ymlextraを出す formatter)に書き直した.ruffG001〜G004,G101,G201,G202,LOG002,LOG015,TRY400が覆う内容は書かないpy_loop_variable_descriptive(削除)N801/N802/N803/N806/N999snake_case; Classes:UpperCamelCaseN)SCREAMING_SNAKE_CASE… module-level constants (two blank lines after imports)Nは定数の大文字を判定しない.意味のある文字列の定数化は下のstring-literal-is-named-constantが判定し,文章も残す)string-literal-is-named-constantmodel-rules/python/string-literal-is-named-constant/rule.yml-er/-orbelong on class namesutils.py/helpers.py.ls-lint.ymlでは書けない)agents/AGENTS.mdの言語非依存の規則が持つ.ruffC901,PLR0912,PLR0915が大きさを一部覆う)withstatements, etc.)C4,PERF,FURBが一部を覆うが,全体は判定できない)ruff formatdecide quotes and operator spacingI001/E301/E302/E305I001,E30x)lines-after-imports = 2lines-after-imports = 2).グローバル変数は文章のままD2xxが一部を覆う.D412/D413は google 規約で無効)import-name-self-explanatoryfrom ... import ...unless the name is self-explanatory; avoidasaliases unless required for claritymodel-rules/python/import-name-self-explanatory/rule.ymlruff formatが決める書式で,規則の対象外)ruff formatの magic trailing comma とE501が長い式を覆う)D100/D101/D102/D103D,google 規約.D104/D105/D107は template が無効)agents/AGENTS.mdが持つ)DOC201/DOC402/DOC501/D417Args,Returns/Yields,Raises)DOC201,DOC402,DOC501,D417)py_definition_order(削除)Enum -> model/class -> functionorderingNameErrorになる例外を判別できない)plain-class-defines-slots(py_plain_class_slotsから降格)__slots__to restrict variables when not usingdataclassesorpydanticcached_propertyの書き方が多い)ため削除model-rules/python/plain-class-defines-slots/rule.ymlpy_dataclass_slotsdataclasses.dataclass(frozen=True, slots=True)py_dataclass_slots.yml(既存)value-object-is-immutablepydantic.BaseModelordataclass(frozen=True, slots=True)model-rules/python/value-object-is-immutable/rule.ymlpy_dataclass_slotsの note と合わせてモデルに任せた__post_init__to enforce invariantsagents/AGENTS.mdの Value Object の規則が持つ)construction-placement-by-puritymodel-rules/python/construction-placement-by-purity/rule.ymlpy_pydantic_base_model_only_in_frozen_base/py_frozen_base_model_config/py_frozen_base_model_no_overrideConfigDict(extra="forbid", frozen=True, strict=True, validate_default=True)/ shared base classBaseModelを直接継承できるのはFrozenBaseModelだけ,そのmodel_configは 5 キー(revalidate_instances="always"を追加)を持つ,サブクラスは 5 キーを上書きしないpy_pydantic_base_model_only_in_frozen_base.yml,py_frozen_base_model_config.yml,py_frozen_base_model_no_override.ymlFrozenBaseModelの例と,pydantic は境界だけという 1 行に置換.旧py_frozen_config_completeは削除)json-parse-uses-model-validate-json(py_pydantic_validate_jsonから降格)model_validate_jsonで読むmodel-rules/python/json-parse-uses-model-validate-json/rule.ymlbase.pyfixed-choices-use-enumEnum/StrEnumfor fixed choices instead of raw string literals or dict mapsmodel-rules/python/fixed-choices-use-enum/rule.ymlagents/AGENTS.mdの「境界で 1 回だけ型に変換する」規則が持つ)UP042StrEnumwhen values are serialized or user-facingUP042.(str, Enum)の混在を覆う.重複する ast-grep 規則py_prefer_strenumは削除)EnumとStrEnumを選ぶ判断は規則が覆わない)py_no_unittestpytestas test frameworkpy_no_unittest.yml(既存)uv run --frozen pytestforbidden_commands.jsonは一部のバイパスしか覆わない)py_no_pytest_asyncioanyiofor async tests, do not useasynciopy_no_pytest_asyncio.yml(pytest.mark.asyncioとpytest_asyncioの import だけを判定.別名の枝は削除)asyncio全般は覆わない)py_async_test_anyio_marker(削除)@pytest.mark.anyioon async testsasync def functions are not natively supported).黙って成功しないので規則は不要anyio_backendfixture の書き方の例)py_no_unittest_mockpytest-mockfor mocking (mockerfixture)py_no_unittest_mock.yml(既存)py_mocker_patch_autospecpy_mocker_patch_autospec.yml(既存)pytest,anyio, andpytest-mockbelong in the template's test dependency grouppyproject.tomlの内容で,Python の構文ではない.依存の検査は deptry の領域)py_xfail_requires_strict@pytest.mark.xfail(strict=True, reason="...")py_xfail_requires_strict.yml(既存)known-defect-marker-names-removalmodel-rules/python/known-defect-marker-names-removal/rule.yml(既存)mutmut(3.x) whentsddcalls for it;[tool.mutmut]config; scope a run; list survivors; keepmutants/out of version control.gitignoreとpyproject.tomlの内容)setup_method/teardown_methodfixture-justified@pytest.fixture: shared setup across 2+ tests, external resources, or teardown; helper function when arguments are needed or setup is light; fixture scope defaultfunctionmodel-rules/python/fixture-justified/rule.ymlrepeated-tests-use-parametrize@pytest.mark.parametrize: same logic with different inputsmodel-rules/python/repeated-tests-use-parametrize/rule.ymluv, don't usepip;uv sync;uv run --frozen {tool};uv add;uv add --group;uv lock --upgrade-package; prohibiteduv pip install,uv add --dev,@latestagents/hooks/rules/forbidden_commands.jsonはpython -m pipだけを覆う.hook の規則の追加はこの PR の範囲外.ast-grep は Python の構文だけを見る)pyproject.tomlの内容)./srcfor production code,./testsfor tests; flat module placement for apps;src/<package_name>/only for distributable packagesE501E501,line-length = 119.URL だけの行は除外される)ANN001/ANN002/ANN003/ANN201/ANN202/ANN204ANN.mainのignoreにANN401は無い)uv run --frozen ty check; do not introduce another type checkertypecheckグループが持つ)project-setup; routine edits do not authorize Nix or GitHub changes判定に使った設定
pyproject.toml(selectにANN,D,E,I,N,PLW,UPなどを含む)をgh apiで確認した.ruff は dev shell にないため規則 ID はローカルで実行せず,ruff の文書上の規則名で対応させた.template repo は変更していない.threshold: 0.5,severity: warning.波 2: linter で有効化する規則
なし.先に挙げた
lines-after-imports = 2,DOC201/DOC402/DOC501,UP042は template-python(#26)のmainで有効なことを確認した.現在の hit(修正はこの PR に含めない)
ローカル checkout に
ast-grep scan --config agents/hooks/lint/sgconfig.yml .を読み取りのみで実行した(新しい Python 規則の分).py_plain_class_slotspy_no_nonlocalpy_multiline_collection(不採用)は同じ方法で agent-config 498 件,dotfiles 89 件の hit があった.検証
nix develop --command uv run --frozen pytest tests/test_ast_grep_rules.py tests/test_model_rule_files.py -q: 55 passednix develop --command ast-grep test --config agents/hooks/lint/sgconfig.yml --skip-snapshot-tests: 全規則 passjev-lint rules --no-config -R agents/hooks/lint/model-rules/python: 10 rule(s) loaded, 0 error(s)ruff check/ruff format --check(tests): passnix develop --command uv run --frozen pytest -q: 4874 passed, 1 skipped🤖 Generated with Claude Code
追加で,Stop の subject 上限を圧迫しないよう広い jev-lint 規則の matcher(import,文字列,固定選択肢)を絞った(#192 のレビュー対応).
後続へ回した指摘(最終方針対応のレビュー上限)
最終方針対応の 3 回目の再レビューが挙げた次の 3 件は修正せず,"Deferred to a follow-up Issue (review limit)." と返信して解決した.
rules/python/py_async_test_anyio_marker.yml: 関数名だけで判定しfiles:の制限がないため,本番コードのasync def test_connection(...)にも error を出す.files:をテストファイル(test_*.py,*_test.py,conftest.py)に絞る.rules/python/py_async_test_anyio_marker.yml:import pytest as ptの別名を,クラス直下のpytestmark = pt.mark.anyioとリスト要素pytestmark = [pt.mark.anyio]にも適用する.rules/python/py_frozen_base_model_config.yml: クラス本体にmodel_configの代入が複数ある場合,最後の代入が完全かどうかを検査する.py_no_pytest_asyncioの別名は,ユーザー決定によりpytest.mark.asyncioとpytest_asyncioの import だけを判定する.後続へ回した指摘(ログ規則追加後のレビュー上限)
次の 4 件は未修正(検出漏れで,誤検出ではない).
py_pydantic_validate_json:data = None; data = json.loads(...)のように loader 代入より前の初期化があると報告しない(検出漏れ).py_pydantic_validate_json:jsonが標準ライブラリでなく独自オブジェクトのとき(import jsonに結び付けていない)も報告する.py_async_test_anyio_marker:anyio_backendを別の fixture(clientや autouse)経由で使う async test は,fixture の依存関係を単一ファイルの構文では解決できないため,まだ未マークとして報告する.py_frozen_base_model_no_override:ConfigDict(**{"frozen": False})のように展開した辞書をbad_pairで検査しない.誤検出の修正(ユーザー許可,10ba684)
blocking にする前の誤検出として,次の 3 件を failing な valid 例を先に足してから直した.
py_pydantic_validate_json(決定変更): loader に追加引数があっても報告し続ける.同じ関数で$D = json.loads(...)(別名,from json import loads [as x],orjson,ujson を含む)として代入した変数をmodel_validate($D)に渡す形も報告する(ast-grep が関係をまたいで$Dを束ねることをテストで確認).json.loadsだけでmodel_validateに渡さない場合は報告しない.py_plain_class_slots/py_dataclass_slots:cached_propertyの別名の除外が,デコレータ付きクラスとネストしたクラスでも効く.py_async_test_anyio_marker:from pytest import markがある場合の bare@mark.usefixtures("anyio_backend")/@mark.anyio,pytestmark = [pytest.mark.usefixtures("anyio_backend"), ...]と[pytest.mark.anyio, ...]のリスト形式を受け入れる.blocking の message と note
ブロックする全規則に,なぜ誤りか(
message)と,そのまま適用できる直し方(note,before/after)を書いた.py_async_test_anyio_markerはfiles:(test_*.py,*_test.py,conftest.py)に限定した.main 取り込み後の対応
testが失敗した原因: main の feat(lint): flag Go packages under util and common with an error rule #202 が「files:で絞った規則はすべて flagged / clean のパスを持つ」テストを足し,py_async_test_anyio_markerが対象になった.main を取り込み,tests/test_ast_grep_rules.pyにこの規則のパスを追加した(全テスト 4921 passed).py_pydantic_validate_json(誤検出,修正済み): loader 代入を探す関数を呼び出しに最も近い関数に限った.外側でdata = json.loads(...),内側の関数が別のdata引数を検証する形を報告しない(valid 例を追加).py_plain_class_slotsは__slots__ = ("__dict__",)を有効扱いする.fix(lint): address review findings deferred from the #74 migration PRs #196 のコメントに追記した.py_pydantic_base_model_only_in_frozen_baseはpydantic.v1.BaseModelを検出しない(検出漏れ).fixture-justifiedは基準の文言が衝突している(advisory).どちらも fix(lint): address review findings deferred from the #74 migration PRs #196 のコメントに追記した.py_async_test_anyio_markerは,別名pytestのusefixtures('anyio_backend')(単引用符)も受け入れる.conftest.pyは対象から外し,py_pydantic_validate_jsonは loader 代入が検証より前にある場合だけ一致する(f8207ea).py_pydantic_validate_jsonは複数名 import(from json import dumps, loads as x)の別名を追跡しない.fix(lint): address review findings deferred from the #74 migration PRs #196 のコメントに追記した.pytestのpytestmark(usefixtures("anyio_backend"),クラス直下のmark.anyio)も受け入れる.pytestのモジュール直下pytestmarkリスト,from functools import lru_cache, cached_property as xの複数名 import(py_dataclass_slotsとpy_plain_class_slots)を受け入れる.py_pydantic_validate_jsonは,無条件の先行代入だけを loader 代入として扱う(ifの中の代入は対象外).note にはstrict=Falseなどの呼び出しオプションを保つ直し方も書いた(7cf166b).py_plain_class_slotsはclass User():とclass User(object):を継承ありとして除外する.fix(lint): address review findings deferred from the #74 migration PRs #196 のコメントに追記した.py_frozen_base_model_configは,5 設定がクラスのキーワードとmodel_configに分かれていても合わせて判定する.py_async_test_anyio_markerはfrom pytest import mark as xの別名も受け入れる.py_pydantic_validate_jsonはfrom json import loads as xを素のloadsとみなさない.anyio_mode = "auto"のプロジェクトではpy_async_test_anyio_markerが誤検出になる.pytest 設定を単一ファイルの規則から読めないため規則内では直せない.fix(lint): address review findings deferred from the #74 migration PRs #196 のコメントに追記した.不安定な規則の整理(上の履歴より新しい)
レビューが収束しなかった次の ast-grep 規則を削除した.上のレビュー対応の記述のうち,これらの規則に関するものは古い.
py_async_test_anyio_marker: 削除.pytest 9.0.3 では,マーカーなしの async test は失敗する(pytest==9.0.3とanyioで使い捨てテストを実行して確認).py_pydantic_validate_json→ jev-lintjson-parse-uses-model-validate-json,py_plain_class_slots→ jev-lintplain-class-defines-slots(advisory,threshold: 0.5,当てはめは延期).規則テストと,これらの規則に関する fix(lint): address review findings deferred from the #74 migration PRs #196 の後続項目は不要になった.ast-grep から外した規則と理由
ブロックする規則は安定していなければならない.次の規則はレビューのたびに新しい指摘が出て収束しなかったため,既存のツールに任せるか jev-lint へ降格することをユーザーが決めた.判断の基準は ADR-0021 に記録する.
py_async_test_anyio_markeranyio_mode = "auto"は pytest 設定,anyio_backendの使用は fixture の依存関係やconftest.py)4) 同じ意味の書き方が多い(
pytestmarkのリストとクラス直下,別名 import,単引用符,usefixturesの引数位置)@pt.mark.usefixtures('anyio_backend'),from pytest import mark as m,class Helper:内のasync def test_x.検出漏れ:anyio_backendを別の fixture 経由で使うpy_pydantic_validate_jsonjson-parse-uses-model-validate-json4) 同じ意味の書き方が多い(
json.loads,別名 import,複数名 import,orjson,ujson)data["id"] = request_idの後のOrder.model_validate(data).検出漏れ:from json import dumps, loads as decode_jsonのdecode_json(raw)py_plain_class_slotsplain-class-defines-slotscached_propertyの別名,class User():)2) データの流れや実行の順番を追う必要がある(
__init__の代入先)from functools import lru_cache, cached_property as cachedを使うクラス.検出漏れ:__slots__ = ("__dict__",),class User(object):py_frozen_base_model_no_overridefrozen-model-subclass-keeps-locked-settings4) 同じ意味の書き方が多い(クラスキーワード,
model_configのConfigDictと辞書)class Money(FrozenBaseModel)の後のclass MutableMoney(Money, strict=False).誤検出: 5 設定がクラスキーワードとmodel_configに分かれた定義py_frozen_base_model_configfrozen-base-model-sets-all-settingsmodel_configの再代入)4) 同じ意味の書き方が多い(クラスキーワード,
ConfigDictと辞書,分割した定義)model_config = COMPLETE_CONFIG(定数に 5 設定が入っている).検出漏れ:model_configを再代入して設定を失う指摘数は,この PR のレビュースレッドのうち,規則ファイルのパスに付いたものの数.
json-parse-uses-model-validate-jsonの基準は,object_hookやparse_floatなどの変換オプション付きのjson.loadsをmodel_validate_jsonと同等とみなさない.