Skip to content

fix(lint): widen three Python model-rule selectors deferred in #196 - #258

Merged
furedea merged 4 commits into
mainfrom
fix/196-python-rules
Nov 20, 2026
Merged

furedea merged 4 commits into
mainfrom
fix/196-python-rules

Conversation

@furedea-agent

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

Copy link
Copy Markdown
Contributor

概要

#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 が増える(fix(lint): address review findings deferred from the #74 migration PRs #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

- no-reaching-through-collaborators: select a chain of three member
  accesses whether or not a call ends it (`order.customer.address.city`).
- no-exposed-mutable-collection: select a function that returns a public
  field as it is (`return self.items`), not only a private one.
- no-comment-restating-code: select a function or its decorators placed
  just below a comment that is not a tool directive.

Each suite gains a fixture for the new shape. The matcher change makes
the saved baselines stale; they need `jev-lint eval --accept`.

Refs #196

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

furedea commented Nov 19, 2026

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 19, 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-19T12:23:17.836179Z a70d16d 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: no correctness or security bugs found in the selector changes. The new fixture line numbers in the three expect.yml files match the fixture files, and the new tests cover each widened selector.

  • P1: the three changed matchers invalidate their baseline.json files, so the replay test (test_every_saved_eval_baseline_still_scores_as_accepted) fails after merge. The PR description says so itself. The baselines need regenerating and committing before merge, and the cutoff comments in the three rule.yml files will then need updating. Inline comment posted on no-exposed-mutable-collection/rule.yml.
  • Not verified: I could not run sg or pytest in this sandbox. One thing worth a quick check: the new follows: comment branch may also select a function that follows a trailing inline comment on the previous statement (x = 1 # note directly above def). It is only a broader matcher and is advisory, so I did not file it as a finding.

@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: 7f21bb88ed

ℹ️ 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".

…lper

The comment rule now also selects a comment just above a function, so its
question names that place too. The bad fixture becomes a private helper:
a comment on a public function documents its API, which the criteria
exempt.

Refs #196

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

furedea commented Nov 19, 2026

Copy link
Copy Markdown
Owner

@codex review

@github-actions

Copy link
Copy Markdown

Review summary

I read the diff only. I did not run the tests or the selectors, because the sandbox blocked my script that runs sg.

P1: merge blocker the PR already discloses. The three changed matchers invalidate their baseline.json files, so test_every_saved_eval_baseline_still_scores_as_accepted (jev-lint eval --replay) fails with "question changed". The suite stays red until someone runs the jev-lint eval --accept command from the PR description. After that, adjust the rule.yml cutoffs and the baseline-dated comments. The no-comment-restating-code header still says "3 violations, 5 conforming cases".

P2 (inline): no-comment-restating-code. follows: kind: comment matches the immediately preceding sibling, so blank lines don't matter. A trailing comment on the previous statement, or a detached section banner, will select the next function. Nothing in the tests covers those shapes.

P3 (inline): no-exposed-mutable-collection. return self.<name> selects every public scalar getter. This is consistent with the "broad matcher" policy, but it adds noise and cost.

The Demeter selector change ($A.$B.$C.$D) looks right, and its test covers the 2-access versus 3-access boundary. The fixture line numbers I checked look consistent, for example everyone at line 95.

@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: 7ab1c1391a

ℹ️ 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 #196

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

furedea commented Nov 19, 2026

Copy link
Copy Markdown
Owner

@codex review

@github-actions

Copy link
Copy Markdown

Review summary

I found one blocking problem and one optional improvement. I read the diff without running the test suite.

  • P1, stale baselines: The new selectors invalidate baseline.json for all three changed rules. tests/test_model_rule_files.py runs jev-lint eval --replay in the normal uv run pytest --cov CI step, so CI will fail on these three suites until the baselines are re-accepted. The PR body already says this is pending, but it needs to be done before merge. After re-accepting, check each rule's threshold and the cutoff comments, for example the 0.30 and 0.86 margins in no-comment-restating-code/rule.yml.
  • P3, comment selector: follows: kind: comment also selects a function that follows a trailing comment on the previous statement, or the last line of a multi-line comment block. That adds some advisory noise only, which fits the "match broadly" policy. It could be recorded as a Limit.

The selector logic otherwise looks right. The no-exposed-mutable-collection regex matches return self.items but not len(self.items) or self.items.copy(). The Demeter pattern needs three member accesses, so user.address.street is excluded. The new tests cover each case.

🤖 Generated with Claude Code

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: 5d3575357f

ℹ️ 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".

The user re-ran `jev-lint eval --accept` for the three suites whose
matchers changed. no-comment-restating-code moves to 0.62 and drops its
stale inconclusive exemption; the other two keep their cutoffs. The
property-chain and above-function cases score under the conforming
range and are recorded as Limits.

Refs #196

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

furedea commented Nov 19, 2026

Copy link
Copy Markdown
Owner

@codex review

@github-actions

Copy link
Copy Markdown

Review summary

No blocking findings (no P0 or P1). I read the three rule.yml changes, the fixtures, expect.yml, and the new selector tests. I did not run the eval suite or ast-grep: the local sg binary is not ast-grep, so none of this was executed.

What looks right:

  • All three rules stay advisory, matching ADR-0027 and the PR description.
  • The widened selectors match the new tests:
    • $A.$B.$C.$D selects order.customer.address.city, and two-access chains stay out.
    • The returned-field regex selects return self.items and skips len(self.items).
    • The comment rule's follows branch plus the decorated_definition branch cover the comment-above-function and comment-above-decorator cases, and the tool-directive regex excludes # noqa.
  • The thresholds are re-derived from the new baselines, and the rule comments say what they cannot separate.

Notes, none of which should block the merge:

  • P3: In no-comment-restating-code/rule.yml, follows: kind: comment only checks the immediately preceding sibling. In tree-sitter, a trailing inline comment on the previous statement (X = 1 # why) is a sibling comment, so it probably selects the next function even though it belongs to the previous line. I could not confirm this by running it. The cost is extra model calls, not wrong verdicts.
  • P3: Two of the three widened selectors are selected but not detected, and the rule comments say so.
    • The comment-above-function case (_total_price) scores 0.11 against a 0.62 cutoff.
    • The property-chain case scores 0.68, between conforming cases at 0.67 and 0.72.
    • Both selectors therefore add model calls without changing what the rules report. That is consistent with the fix(lint): address review findings deferred from the #74 migration PRs #196 approach of matching broadly and leaving the judgment to the criteria.
  • P3: no-exposed-mutable-collection still selects any return self.<public_field>, including strings and ints such as label returning self.text. This is why test_agents_md_model_rules.py now expects 2. It is acknowledged and the criteria filter it.

Test coverage: each selector change has a Red/Green selector test. There is no test for the trailing-comment case above.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: a70d16d5f6

ℹ️ 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 b3fc801 into main Nov 20, 2026
29 checks passed
@furedea
furedea deleted the fix/196-python-rules branch November 20, 2026 06:07
furedea pushed a commit that referenced this pull request Nov 20, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.3.1](v0.3.0...v0.3.1)
(2026-11-20)


### Bug Fixes

* **hooks:** do not count a printf whose format holds %n as writing
nothing ([#262](#262))
([f3a4543](f3a4543))
* **hooks:** judge gh beside commands that write nothing as gh alone
([#256](#256))
([540bbad](540bbad))
* **hooks:** stop asking for gh calls whose target and arguments are
known at hook time
([#254](#254))
([f4aa355](f4aa355))
* **lint:** close the Rust and TypeScript items of
[#196](#196)
([#259](#259))
([1d2a81e](1d2a81e))
* **lint:** select the Go model-rule forms deferred in
[#196](#196)
([#257](#257))
([8c347fe](8c347fe))
* **lint:** widen three Python model-rule selectors deferred in
[#196](#196)
([#258](#258))
([b3fc801](b3fc801))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: furedea-release[bot] <353651101+furedea-release[bot]@users.noreply.github.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