Skip to content

feat(lint): migrate python-style rules to ast-grep and model rules - #192

Merged
furedea merged 42 commits into
mainfrom
feat/migrate-python-style-rules
Nov 15, 2026
Merged

furedea merged 42 commits into
mainfrom
feat/migrate-python-style-rules

Conversation

@furedea-agent

@furedea-agent furedea-agent Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

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-style skill の文章規則を 1 規則ずつ棚卸しし,最も安い判定手段へ移した(ADR-0020,ADR-0021).

  • 既存 linter(ruff)が既に覆う文章は削除し,対応する規則 ID を表に書いた.
  • ast-grep 規則を 8 件追加し,rule-tests を各規則に valid / invalid 各 3 件以上付けた.
  • jev-lint 規則(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.

規則 ID 元の場所 元の規則(原文) 判定 実装 例のテスト 元の文章
py_no_nonlocal references/code_style.md(Functions) Don't use global, nonlocal 静的(ast-grep).global は既存 linter(ruff PLW0603) py_no_nonlocal.yml 良 2 / 悪 2 削除(nonlocal は本規則,global は template-python の ruff PLW0603 が置換)
ruff UP006 / UP035 references/code_style.md(Functions) Use built-in generics instead of typing.Tuple, typing.List, typing.Dict 既存 linter(template-python の ruff UP006,UP035.template-python は UP を選択済み) なし なし 削除(template-python で有効な規則が完全に覆う)
py_logging_dict_message(削除)/ py_no_structlog_loguru(新規) references/code_style.md(Logging) Write in dictionary format 辞書形式の規則は削除.標準 logging と extra を使う方針に変え,structlog と loguru の import を禁止する静的規則(ast-grep,error)を追加 py_no_structlog_loguru.yml 良 3 / 悪 5 辞書形式の文章と例を削除.Logging の節を 3 項目(十分なログ,handler と formatter は entry point だけ,extra を出す formatter)に書き直した.ruff G001〜G004,G101,G201,G202,LOG002,LOG015,TRY400 が覆う内容は書かない
py_loop_variable_descriptive(削除) references/code_style.md(Naming) Loop body ≥ 3 lines: descriptive name 規則を削除(名前の良し悪しを形から推測する) なし なし 削除(Iterator arguments の 2 項目とも)
ruff N801 / N802 / N803 / N806 / N999 references/code_style.md(Naming) Variables / functions / files: snake_case; Classes: UpperCamelCase 既存 linter(template-python の ruff N) なし なし 削除(template-python で有効な規則が完全に覆う).「Getters: 出力変数の名前」は残る
(なし) references/code_style.md(Naming) Constants: SCREAMING_SNAKE_CASE … module-level constants (two blank lines after imports) 文章のまま なし なし 残す(ruff N は定数の大文字を判定しない.意味のある文字列の定数化は下の string-literal-is-named-constant が判定し,文章も残す)
string-literal-is-named-constant references/code_style.md(Naming) define semantically meaningful string literals as module-level constants rather than embedding them inline 動的(jev-lint,0.5) model-rules/python/string-literal-is-named-constant/rule.yml 延期 残して併記(ADR-0021)
(なし) references/code_style.md(Naming / Iterator arguments) Loop body ≤ 2 lines: single character 文章のまま なし なし 残す(許可であり,違反を構文で定義できない)
(なし) references/code_style.md(File Naming) Name files after the domain/action, not the role suffix; -er/-or belong on class names 文章のまま なし なし 残す(語の意味の判断で,ls-lint の正規表現(RE2)で書けない)
(なし) references/code_style.md(File Naming) Avoid utils.py / helpers.py 文章のまま なし なし 残す(ls-lint の正規表現(RE2)には否定先読みがなく,template-python の .ls-lint.yml では書けない)
(なし) references/code_style.md(Functions) Keep functions focused and small 文章のまま なし なし 残す(単一責務は agents/AGENTS.md の言語非依存の規則が持つ.ruff C901,PLR0912,PLR0915 が大きさを一部覆う)
(なし) references/code_style.md(Functions) Use Pythonic syntax (comprehensions, with statements, etc.) 文章のまま なし なし 残す(ruff C4,PERF,FURB が一部を覆うが,全体は判定できない)
(なし) references/code_style.md(Formatting) Let ruff format decide quotes and operator spacing 既存 linter(ruff format)への指示 なし なし 残す(ツールの使い方の指示)
ruff I001 / E301 / E302 / E305 references/code_style.md(Whitespace) Two blank lines before/after object (class/function) definitions; one blank line between instance methods and between import groups; Imports: standard library → third-party → local with one blank line 既存 linter(template-python の ruff I001,E30x) なし なし 削除(template-python で有効な規則が完全に覆う)
ruff isort lines-after-imports = 2 references/code_style.md(Whitespace) Two blank lines before/after import statements and global variable definitions 既存 linter(template-python の lines-after-imports = 2).グローバル変数は文章のまま なし なし import の行を削除.「グローバル変数の前後 2 行」は ruff に規則がないので残す
(なし) references/code_style.md(Whitespace) One blank line between docstring sections 文章のまま なし なし 残す(ruff D2xx が一部を覆う.D412 / D413 は google 規約で無効)
import-name-self-explanatory references/code_style.md(Imports) Avoid from ... import ... unless the name is self-explanatory; avoid as aliases unless required for clarity 動的(jev-lint,0.5) model-rules/python/import-name-self-explanatory/rule.yml 延期 残して併記(ADR-0021)
(なし) references/code_style.md(Indentation) When handling multiple objects in parallel, align indentation with the previous element 文章のまま なし なし 残す(ruff format が決める書式で,規則の対象外)
(なし) references/code_style.md(Line Breaks) One element per line for lists/dicts with 3+ items or long expressions; trailing comma 文章のまま(ast-grep は不採用) なし なし 残す(3 要素以上の 1 行リテラルを ast-grep で試すと agent-config で 498 件,中央値 50 文字の短い定数が大半で,誤検出が多すぎた.ruff format の magic trailing comma と E501 が長い式を覆う)
(なし) references/code_style.md(Line Breaks) Don't sacrifice readability for brevity 文章のまま なし なし 残す(判断の指針)
(なし) references/code_style.md(Comments & Docstrings) Write comments on their own line above the relevant code 文章のまま なし なし 残す(行末コメントは ast-grep が行の位置を比較できず,ruff にも禁止規則がない)
ruff D100 / D101 / D102 / D103 references/code_style.md(Comments & Docstrings) Always add docstrings to public APIs 既存 linter(template-python の ruff D,google 規約.D104 / D105 / D107 は template が無効) なし なし 削除(template-python で有効な規則が完全に覆う)
(なし) references/code_style.md(Comments & Docstrings) Comment non-obvious choices (algorithm params, fallback behavior, encoding handling) 文章のまま なし なし 残す(何が自明でないかは文脈の判断.コメント最小化は agents/AGENTS.md が持つ)
ruff DOC201 / DOC402 / DOC501 / D417 references/code_style.md(Comments & Docstrings の例) Docstring layout (summary, details, Args, Returns/Yields, Raises) 既存 linter(template-python の DOC201,DOC402,DOC501,D417) なし なし 残す(節の並びと空行,例の書式は規則が覆わない.節の有無は linter が判定する)
py_definition_order(削除) references/models.md(Classes) prefer Enum -> model/class -> function ordering 規則を削除(従うと NameError になる例外を判別できない) なし なし 削除
plain-class-defines-slots(py_plain_class_slots から降格) references/models.md(Classes) Use __slots__ to restrict variables when not using dataclasses or pydantic 動的(jev-lint,advisory,0.5).ast-grep 規則はレビューが収束しない(基底,デコレータ,cached_property の書き方が多い)ため削除 model-rules/python/plain-class-defines-slots/rule.yml 延期 残して併記(ADR-0021)
py_dataclass_slots references/models.md(Value Objects) dataclasses.dataclass(frozen=True, slots=True) 静的(ast-grep,既存) py_dataclass_slots.yml(既存) 既存 変更なし
value-object-is-immutable references/models.md(Value Objects) Value Objects: pydantic.BaseModel or dataclass(frozen=True, slots=True) 動的(jev-lint,0.5) model-rules/python/value-object-is-immutable/rule.yml 延期 残して併記(ADR-0021).値オブジェクトかどうかは構文から判別できないので,py_dataclass_slots の note と合わせてモデルに任せた
(なし) references/models.md(Value Objects) Resolve routine representation choices from existing dependencies and nearby code; ask only when a material decision is not covered 文章のまま なし なし 残す(進め方の指示)
(なし) references/models.md(Value Objects) Use __post_init__ to enforce invariants 文章のまま なし なし 残す(不変条件の有無は構文から判別できない.agents/AGENTS.md の Value Object の規則が持つ)
construction-placement-by-purity references/models.md(Value Objects) Use classmethods as alternative constructors for pure construction; if construction involves I/O, a module-level function 動的(jev-lint,0.5) model-rules/python/construction-placement-by-purity/rule.yml 延期 残して併記(ADR-0021)
py_pydantic_base_model_only_in_frozen_base / py_frozen_base_model_config / py_frozen_base_model_no_override references/models.md(Pydantic) Frozen model config: ConfigDict(extra="forbid", frozen=True, strict=True, validate_default=True) / shared base class 静的(ast-grep,error).BaseModel を直接継承できるのは 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.yml 良 5 / 悪 4,良 3 / 悪 3,良 4 / 悪 4 削除して書き直し(FrozenBaseModel の例と,pydantic は境界だけという 1 行に置換.旧 py_frozen_config_complete は削除)
json-parse-uses-model-validate-json(py_pydantic_validate_json から降格) references/models.md(Pydantic) JSON は model_validate_json で読む 動的(jev-lint,advisory,0.5).データフロー(変数経由,変更の有無)を ast-grep では判定できないため,ast-grep 規則を削除 model-rules/python/json-parse-uses-model-validate-json/rule.yml 延期 文章は残す(pydantic の節の 1 文)
(なし) references/models.md(Pydantic) When multiple frozen models exist, extract a shared base class to base.py 文章のまま なし なし 残す(複数ファイルにまたがる重複の判断で,1 ファイルの構文から判別できない)
fixed-choices-use-enum references/models.md(Enums) Use Enum/StrEnum for fixed choices instead of raw string literals or dict maps 動的(jev-lint,0.5) model-rules/python/fixed-choices-use-enum/rule.yml 延期 残して併記(ADR-0021)
(なし) references/models.md(Enums) Convert user input strings to Enum early, then map through Enum values 文章のまま なし なし 残す(境界での変換の位置は agents/AGENTS.md の「境界で 1 回だけ型に変換する」規則が持つ)
ruff UP042 references/models.md(Enums) Prefer StrEnum when values are serialized or user-facing 既存 linter(template-python の UP042.(str, Enum) の混在を覆う.重複する ast-grep 規則 py_prefer_strenum は削除) なし なし 残す(直列化や表示の有無で Enum と StrEnum を選ぶ判断は規則が覆わない)
py_no_unittest references/testing.md Use pytest as test framework 静的(ast-grep,既存) py_no_unittest.yml(既存) 既存 変更なし(「pytest を使う」の指示は残る)
(なし) references/testing.md Run tests using uv run --frozen pytest 文章のまま なし なし 残す(コマンドの指示.forbidden_commands.json は一部のバイパスしか覆わない)
py_no_pytest_asyncio references/testing.md Use anyio for async tests, do not use asyncio 静的(ast-grep) py_no_pytest_asyncio.yml(pytest.mark.asyncio と pytest_asyncio の import だけを判定.別名の枝は削除) 良 3 / 悪 4 残す(規則は pytest-asyncio の marker と import だけを判定し,asyncio 全般は覆わない)
py_async_test_anyio_marker(削除) references/testing.md(Async test pattern) @pytest.mark.anyio on async tests 規則を削除.pytest 9.0.3 は,どのプラグインも実行しない async test を失敗にする(使い捨てテストで確認: async def functions are not natively supported).黙って成功しないので規則は不要 なし なし 残す(anyio_backend fixture の書き方の例)
py_no_unittest_mock references/testing.md Use pytest-mock for mocking (mocker fixture) 静的(ast-grep,既存) py_no_unittest_mock.yml(既存) 既存 変更なし(「mocker を使う」の指示は残る)
py_mocker_patch_autospec references/testing.md (autospec) 静的(ast-grep,既存) py_mocker_patch_autospec.yml(既存) 既存 変更なし
(なし) references/testing.md pytest, anyio, and pytest-mock belong in the template's test dependency group 文章のまま なし なし 残す(pyproject.toml の内容で,Python の構文ではない.依存の検査は deptry の領域)
py_xfail_requires_strict references/testing.md Record a reproduced defect with @pytest.mark.xfail(strict=True, reason="...") 静的(ast-grep,既存) py_xfail_requires_strict.yml(既存) 既存 変更なし
known-defect-marker-names-removal references/testing.md …and a comment naming the condition for removing the marker 動的(jev-lint,既存,0.5) model-rules/python/known-defect-marker-names-removal/rule.yml(既存) 既存 変更なし
(なし) references/testing.md Remove the marker in the change that fixes the defect 文章のまま なし なし 残す(変更の進め方.差分の文脈が要る)
(なし) references/testing.md(Mutation Testing) Use mutmut (3.x) when tsdd calls for it; [tool.mutmut] config; scope a run; list survivors; keep mutants/ out of version control 文章のまま なし なし 残す(ツールの使い方と設定..gitignore と pyproject.toml の内容)
(なし) references/testing.md(Test Structure) Function-based by default; class only for namespace grouping or setup_method/teardown_method 文章のまま なし なし 残す(namespace のための class を許すので,違反を構文で定義できない)
fixture-justified references/testing.md(Test Structure) @pytest.fixture: shared setup across 2+ tests, external resources, or teardown; helper function when arguments are needed or setup is light; fixture scope default function 動的(jev-lint,0.5) model-rules/python/fixture-justified/rule.yml 延期 残して併記(ADR-0021)
repeated-tests-use-parametrize references/testing.md(Test Structure) @pytest.mark.parametrize: same logic with different inputs 動的(jev-lint,0.5) model-rules/python/repeated-tests-use-parametrize/rule.yml 延期 残して併記(ADR-0021)
(なし) references/tooling.md(Package Management) Use only uv, don't use pip; uv sync; uv run --frozen {tool}; uv add; uv add --group; uv lock --upgrade-package; prohibited uv pip install, uv add --dev, @latest 文章のまま なし なし 残す(シェルコマンドの規則.agents/hooks/rules/forbidden_commands.json は python -m pip だけを覆う.hook の規則の追加はこの PR の範囲外.ast-grep は Python の構文だけを見る)
(なし) references/tooling.md(Package Management) Baseline tooling dependencies belong in template-defined dependency groups 文章のまま なし なし 残す(pyproject.toml の内容)
(なし) references/tooling.md(Directory Structure) ./src for production code, ./tests for tests; flat module placement for apps; src/<package_name>/ only for distributable packages 文章のまま なし なし 残す(設計判断.ディレクトリの構成は ls-lint の対象外)
ruff E501 references/tooling.md(File Standards) Keep code within 119 characters per line (URLs may exceed this limit) 既存 linter(template-python の ruff E501,line-length = 119.URL だけの行は除外される) なし なし 削除(template-python で有効な規則が完全に覆う)
ruff ANN001 / ANN002 / ANN003 / ANN201 / ANN202 / ANN204 references/tooling.md(File Standards) Always include type hints 既存 linter(template-python の ruff ANN.main の ignore に ANN401 は無い) なし なし 削除(template-python で有効な規則が完全に覆う)
(なし) references/tooling.md(File Standards / Static Type Checking) Use ty for static type checking; run uv run --frozen ty check; do not introduce another type checker 文章のまま なし なし 残す(ツールの選択とコマンド.ty 自体は template の typecheck グループが持つ)
(なし) SKILL.md(Scope) Scope: code inside a bootstrapped project; setup belongs to project-setup; routine edits do not authorize Nix or GitHub changes 文章のまま なし なし 残す(skill の適用範囲と権限の境界)
(なし) SKILL.md(Task-Specific References) Read only the references relevant to the current task 文章のまま なし なし 残す(進め方の指示)

判定に使った設定

  • ruff は template-python の pyproject.toml(select に ANN,D,E,I,N,PLW,UP などを含む)を gh api で確認した.ruff は dev shell にないため規則 ID はローカルで実行せず,ruff の文書上の規則名で対応させた.template repo は変更していない.
  • jev-lint の規則は advisory(ADR-0021).Stop の共通 gate は未判定の入力の指摘を 1 回だけ報告して止める(既存の未当てはめ規則と同じ挙動で,hook の変更はこのレーンの範囲外).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 規則の分).

repo 規則 hit 場所
agent-config py_plain_class_slots 6 scripts/replay_commands.py:174,agents/hooks/lib/shell_paths.py:101,agents/hooks/lib/provider_adapter.py:92,tests/skills/test_skill_commands.py:68,tests/hooks/test_trusted_owners_fallback.py:45,tests/hooks/test_static_rules.py:27
agent-config py_no_nonlocal 1 agents/hooks/lib/check_execution.py:138
agent-config その他の新規則 0 なし
agent-harness 新規則すべて 0 Python の対象がほぼない
dotfiles 新規則すべて 0 なし

py_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 passed
  • nix develop --command ast-grep test --config agents/hooks/lint/sgconfig.yml --skip-snapshot-tests: 全規則 pass
  • jev-lint rules --no-config -R agents/hooks/lint/model-rules/python: 10 rule(s) loaded, 0 error(s)
  • jev-lint の dry-run で,7 件の matcher が想定した subject を選ぶことを確認した(モデルの判定は延期)
  • ruff check / ruff format --check(tests): pass
  • 全テスト: nix 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 のコメントに追記した.
  • 誤検出の修正(8bb159c): 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 のコメントに追記した.
  • 誤検出の修正(b402713,d5931b5): 別名 pytest の pytestmark(usefixtures("anyio_backend"),クラス直下の mark.anyio)も受け入れる.
  • 後続へ回した指摘(未修正,検出漏れ): 別名の分岐は receiver を厳密に別名へ結び付けていない.fix(lint): address review findings deferred from the #74 migration PRs #196 のコメントに追記した.
  • 誤検出の修正(0ea63c6): 別名 pytest のモジュール直下 pytestmark リスト,from functools import lru_cache, cached_property as x の複数名 import(py_dataclass_slots と py_plain_class_slots)を受け入れる.
  • 誤検出の修正(04fc613): 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 のコメントに追記した.
  • 誤検出の修正(2ba6e0b): py_frozen_base_model_config は,5 設定がクラスのキーワードと model_config に分かれていても合わせて判定する.py_async_test_anyio_marker は from pytest import mark as x の別名も受け入れる.
  • 誤検出の修正(bccac41): 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-lint json-parse-uses-model-validate-json,py_plain_class_slots → jev-lint plain-class-defines-slots(advisory,threshold: 0.5,当てはめは延期).規則テストと,これらの規則に関する fix(lint): address review findings deferred from the #74 migration PRs #196 の後続項目は不要になった.
  • 全テスト: 4913 passed, 1 skipped.

ast-grep から外した規則と理由

ブロックする規則は安定していなければならない.次の規則はレビューのたびに新しい指摘が出て収束しなかったため,既存のツールに任せるか jev-lint へ降格することをユーザーが決めた.判断の基準は ADR-0021 に記録する.

規則 行き先 review の指摘数 不安定の型 例
py_async_test_anyio_marker 削除.pytest 9.0.3 が,どのプラグインも実行しない async test を失敗にする(使い捨てテストで確認) 34 1) ファイルの外の情報が要る(anyio_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_json jev-lint json-parse-uses-model-validate-json 17 2) データの流れや実行の順番を追う必要がある(変数に代入してから検証,代入の前後,条件付き代入,検証前の変更)
4) 同じ意味の書き方が多い(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_slots jev-lint plain-class-defines-slots 11 4) 同じ意味の書き方が多い(基底クラス,デコレータ,cached_property の別名,class User():)
2) データの流れや実行の順番を追う必要がある(__init__ の代入先)
誤検出: from functools import lru_cache, cached_property as cached を使うクラス.検出漏れ: __slots__ = ("__dict__",),class User(object):
py_frozen_base_model_no_override jev-lint frozen-model-subclass-keeps-locked-settings 4 2) データの流れや実行の順番を追う必要がある(クラスの継承を複数のクラスやファイルにまたがって追う)
4) 同じ意味の書き方が多い(クラスキーワード,model_config の ConfigDict と辞書)
検出漏れ: class Money(FrozenBaseModel) の後の class MutableMoney(Money, strict=False).誤検出: 5 設定がクラスキーワードと model_config に分かれた定義
py_frozen_base_model_config jev-lint frozen-base-model-sets-all-settings 8 2) データの流れや実行の順番を追う必要がある(名前付きの設定定数,model_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 と同等とみなさない.

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>
@furedea

furedea commented Nov 13, 2026

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-15T14:23:51.656230Z f816b76 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

Copy link
Copy Markdown

Review summary (read-only)

No blocking findings (no P0 or P1). Three inline comments:

  • P2 value-object-is-immutable: the pydantic branch never matches pydantic.BaseModel, the form the style guide recommends. It is an attribute node, and the inner has only checks direct identifier children.
  • P3 py_plain_class_slots: an annotated __slots__: tuple[str, ...] = ... doesn't count as having slots, so the rule flags it wrongly.
  • P3 py_definition_order: the Enum regex matches FlagEnum/IntFlagEnum instead of Flag/IntFlag, and misses enum.Enum.

Checked with no issues found: the other ast-grep rules and their rule-tests, the other jev-lint matchers, the narrower RULE_IDS filter in tests/test_model_rule_files.py, and the edits to the skill text. ast-grep isn't installed in this environment, so I didn't run the rules. The findings above come from reading the tree-sitter grammar.

🤖 Generated with Claude Code

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 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>
@furedea

furedea commented Nov 14, 2026

Copy link
Copy Markdown
Owner

@codex review

@github-actions

Copy link
Copy Markdown

Review summary

No blocking findings (0 × P0, 0 × P1). The new ast-grep findings are advisory: static_rule_scan reports them and never fails the hook. The jev-lint rules are advisory too (ADR-0021). So the problems below are false positives or missed cases. None of them breaks anything when merged.

Inline findings

  • P2 py_definition_order: flags definitions that an Enum depends on (a mixin base class, or a class or function used for a member value). The message tells the agent to move them after the Enum, which causes a NameError on import.
  • P3 py_async_test_anyio_marker: the pytestmark regex doesn't match a multi-line list, so every async test in such a module gets flagged.
  • P3 py_prefer_strenum: misses (str, enum.Enum).

Checked and found OK: the py_frozen_config_complete, py_logging_dict_message, py_no_nonlocal, py_no_pytest_asyncio and py_plain_class_slots matchers; the prose removals, each of which matches a ruff rule template-python enables; the narrowed assertion in tests/test_model_rule_files.py, which still checks the three original rules exactly.

Not verified locally: ast-grep and jev-lint weren't runnable in the review environment, so I reviewed the rules by reading them. One thing to confirm: string-literal-is-named-constant uses a parent: key, which isn't a standard ast-grep relational key. If jev-lint quietly ignores unknown keys, the docstring exclusion won't work as intended. The PR's dry-run results suggest it loads, but it's worth checking.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 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>
@furedea

furedea commented Nov 14, 2026

Copy link
Copy Markdown
Owner

@codex review

@github-actions

Copy link
Copy Markdown

Review summary

No blocking findings (0 × P0/P1).

These are new ast-grep rules and jev-lint model rules. They are advisory: static_rule_scan only reports findings and never gates. I didn't find any correctness or security problem that should block the merge. The tests/test_model_rule_files.py change is narrow and correct: counts are now compared only for the existing RULE_IDS.

Inline findings:

  • P2 py_loop_variable_descriptive: no test covers the threshold (a single-character variable with a 2-line body should be valid).
  • P3 py_logging_dict_message: flags a dict passed as a variable or built with dict(...).
  • P3 py_async_test_anyio_marker: flags async tests that request the anyio_backend fixture, which anyio runs without a marker.
  • P3 py_frozen_config_complete: ignores model_config inherited from a frozen base class.

Note: I couldn't run ast-grep test in this environment, so the rule-test results were not checked here. CI covers them through test_ast_grep_accepts_every_valid_case_and_reports_every_invalid_case.

…wer false positives

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 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".

@furedea

furedea commented Nov 14, 2026

Copy link
Copy Markdown
Owner

@codex review

Comment thread tests/test_model_rule_files.py Resolved
@github-actions

Copy link
Copy Markdown

レビュー概要

正しさ,セキュリティ,テストの不足を見た.merge を止める指摘(P0/P1)は無い.

  • [P2] py_definition_order: inside: kind: module の対象が module 直下の節点だけなので,デコレータ付きのクラスや関数(@dataclass)と,デコレータ付きの Enum(@unique)を見落とす.rule-tests にもその例が無い.
  • [P3] tests/test_model_rule_files.py: 比較を RULE_IDS に絞ったため,新しい Python model rule 7 件の選択条件を確かめるテストが無い(fixtures は延期済み).

補足:

  • ast-grep の追加規則と model rule はどれも severity が warning で,PostToolUse の追加文脈として出るだけなので,誤検出があっても作業は止まらない.
  • 共有テストの変更は確認した.他の Python 用テスト(other.py,未追跡ファイルのケース)は新しい規則を入れても期待値が変わらないはず.
  • 削除した文章が template-python 側の ruff 設定(PLW0603,N,UP など)で覆われているかは,このリポジトリからは確かめられなかった.
  • この環境では ast-grep と jev-lint を動かしていないので,rule-tests の合否は CI に任せる.

🤖 Generated with Claude Code

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 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>
@furedea

furedea commented Nov 15, 2026

Copy link
Copy Markdown
Owner

@codex review

@github-actions

Copy link
Copy Markdown

Review summary (read-only)

Blocking (P0/P1): none.

  • P2: The new fix instructions in the rules' note: never reach the agent. agents/hooks/lib/static_rule_scan.py finding() shows only message. Several existing rules (py_no_staticmethod, py_no_unittest, py_xfail_requires_strict, …) moved their fix from message into note, so they now say what is wrong but not how to fix it. See the inline comment.

Other checks:

  • I read the new ast-grep rules (py_frozen_base_model_config, py_frozen_base_model_no_override, py_pydantic_base_model_only_in_frozen_base, py_no_structlog_loguru, py_no_pytest_asyncio, py_no_nonlocal) and the cached_property alias exclusion in py_dataclass_slots. I found no false positive in them beyond the gaps the PR description already defers.
  • The hook reports findings as advisory context and does not branch on severity. Moving these rules to error therefore does not block edits to existing violations such as agents/hooks/lib/check_execution.py:138 (nonlocal).
  • ast-grep and jev-lint are not installed in the review environment, so I could not run the rule tests here. I relied on reading the rules and on the test results in the PR description.

🤖 Generated with Claude Code

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 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".

@furedea

furedea commented Nov 15, 2026

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 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>
@furedea

furedea commented Nov 15, 2026

Copy link
Copy Markdown
Owner

@codex review

@github-actions

Copy link
Copy Markdown

Review summary (read-only)

No blocking findings.

Reviewed:

  • New ast-grep rules: py_frozen_base_model_config, py_pydantic_base_model_only_in_frozen_base, py_no_structlog_loguru, py_no_pytest_asyncio, py_no_nonlocal.
  • The aliased cached_property exclusion in py_dataclass_slots.
  • The severity change from warning to error.
  • The 10 jev-lint model rules and the subject-count test in tests/test_python_model_rules.py.
  • The narrowed comparison in tests/test_model_rule_files.py.

What I checked:

  • The import-matching regexes do not match lookalike modules (structlog_x, pydantic.v1, sqlmodel.BaseModel) and do catch the forms they are meant to catch: aliases, parenthesized imports, multi-name import.
  • I traced the expected subject counts in the new test against each rule's selector. Example: data["v"] is too short for the 3+ character literal regex, so string-literal-is-named-constant = 2 is consistent.
  • py_mocker_patch_autospec still skips a positional new, which matches the old behavior.

Minor note, not filed as a finding: pydantic applies class keywords after model_config. So class FrozenBaseModel(pydantic.BaseModel, frozen=False) with a complete model_config would pass py_frozen_base_model_config and still not be frozen. This is contrived and the advisory model rule covers subclasses, so I'm only mentioning it.

I could not run ast-grep test in this environment. Verification relied on reading the rules and their rule-tests.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 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".

@furedea

furedea commented Nov 15, 2026

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 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>
@furedea

furedea commented Nov 15, 2026

Copy link
Copy Markdown
Owner

@codex review

@github-actions

Copy link
Copy Markdown

Review summary

Read-only review of the new ast-grep rules, jev-lint model rules, skill text changes and tests.

  • P1 py_no_pytest_asyncio: the import patterns most likely miss dotted modules (import pytest_asyncio.plugin, from pytest_asyncio.plugin import fixture). Those are listed as invalid cases in the rule tests, so ast-grep test (and test_ast_grep_accepts_every_valid_case_and_reports_every_invalid_case) should fail. Real imports of that form would also go unflagged. I couldn't run ast-grep in this environment, so please confirm locally.
  • P3 json-parse-uses-model-validate-json: the regex runs on the whole call text, so a call that wraps a model_validate(...) call becomes a second subject.

Nothing else blocking. The other rule matchers agree with the subject counts in tests/test_python_model_rules.py, and the shared-test change in test_model_rule_files.py is correctly limited to RULE_IDS.

Blocking findings (P0/P1): 1

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 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".

@furedea
furedea merged commit 4de33a2 into main Nov 15, 2026
24 of 27 checks passed
@furedea
furedea deleted the feat/migrate-python-style-rules branch November 15, 2026 14:32
furedea-agent Bot pushed a commit that referenced this pull request Nov 15, 2026
Add the stability criteria and the evidence from PRs #192-#195 to ADR-0021,
point rule authors to it from sgconfig.yml, and make the skill layout test
ignore hidden directories such as an untracked agents/skills/.claude.

Refs #74
Refs #196

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
furedea added a commit that referenced this pull request Nov 15, 2026
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>
furedea added a commit that referenced this pull request Nov 16, 2026
## 概要

#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>
furedea added a commit that referenced this pull request Nov 20, 2026
…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>
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