Repository navigation
build(oxlint): enable caught-error cause and unsafe-any type rules - #44
Conversation
Refs furedea/agent-config#74 Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
|
@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 This PR only changes config: it adds No findings (0 blocking). Note: I didn't run the linters myself because dependencies aren't installed in the review environment. The rule behavior described here comes from the PR description. |
|
Codex Review: Didn't find any major issues. Another round soon, please! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
…checks (#195) Refs #74(TypeScript 担当) Refs #196 計画:#74 (comment) ## 概要 `agents/skills/typescript-style/` の規則を 1 文ずつ洗い出し,判定できる最も安い道具へ移した(ADR-0021). - **ast-grep(最終)**: この PR が残す TypeScript の ast-grep 規則は 0 件.不安定な 3 規則(`ts_no_unvalidated_json_cast`,`ts_catch_rethrow_requires_cause`,`ts_no_other_test_framework`)は review が収束しないため削除し,oxlint へ移す(下の「ast-grep から外した規則と理由」). - **ast-grep(削除)**: `ts_readonly_property`,`ts_readonly_array_property`,`ts_no_home_dir_in_tests`(文章は残す),`ts_no_namespace_import`(規則も文章も削除). - **jev-lint**: 8 規則を `model-rules/typescript/<id>/rule.yml` に追加(`threshold: 0.5`,`severity: warning`).prose は残す(ADR-0021).fixture・eval・baseline は未追加. - **既存 linter が覆う文章**は,template-typescript の `main` で有効な規則を確かめ,同じ PR で削除した.完全には覆われない部分は残した. - **共有ファイルの変更**: `tests/test_model_rule_files.py` の TypeScript 用の選択数テストだけ(jev 規則の追加に伴う期待値の更新). ## 最終の ast-grep 規則 なし(TypeScript の blocking な ast-grep 規則は残さない). ## ast-grep から外した規則と理由 blocking にする規則は安定していなければならない.次の規則は review のたびに新しい指摘が出て収束しなかった(11〜26 件)ため,既存の linter に任せることにした.判断の基準は ADR-0021 に記録する. | 規則 | 行き先 | review の指摘数 | 不安定の型 | 例 | | --- | --- | --- | --- | --- | | `ts_no_unvalidated_json_cast` / `tsx_` | oxlint `typescript/no-unsafe-type-assertion`,`no-unsafe-assignment`,`no-unsafe-return`(furedea/template-typescript#44) | 26 | 1(変数の宣言型や import 先を見られない),4(`as` / `<T>` / `!` / `satisfies` / 注釈 / 戻り値型の書き方が多い) | 誤検出:`const x: unknown \| null = JSON.parse(t)`.見逃し:`JSON.parse(t) as Record<string, unknown>` | | `ts_catch_rethrow_requires_cause` / `tsx_` | oxlint `preserve-caught-error`(furedea/template-typescript#44) | 11 | 2(捕捉した値が使われるかを追う),4(`new` なし,`cause` の渡し方,`.catch` など) | 誤検出:`new AppError({ message, cause: error })`.見逃し:`new Error(message)` | | `ts_no_other_test_framework` / `tsx_` | oxlint `no-restricted-globals`(スコープを見る)と `no-restricted-imports`(template-typescript の新しい PR.番号は作成後に追記) | 12 | 2(`jest` が局所変数・引数・分割代入・`catch` の引数などに隠されるかをスコープで追う) | 誤検出:`const { jest } = makeFormatters(); jest.format()`,`catch (jest) { jest.format() }` | 文章(typescript-style)は,template の PR がマージされるまで残す. ## 文章と規則の対応表(全規則) 場所は `agents/skills/typescript-style/` からの相対パス,実装は `agents/hooks/lint/` からの相対パス. | 規則 ID | 元の場所 | 元の規則(原文) | 判定 | 実装 | 例のテスト | 元の文章 | | ------------------------------------------- | ------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------- | ---------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | (削除)ts_no_namespace_import | references/code_style.md(#117 で削除済み) | 名前空間 import を避ける | 規則を削除 | — | — | 文章は #117 で削除済み.ユーザーの判断で規則(`ts_` / `tsx_`)も削除した(Zod 4 が `import * as z from "zod"` を勧めるなど,名前空間 import は問題ない) | | (ls-lint) | references/code_style.md | Use snake_case file names (enforced by ls-lint) | 既存 linter(template-typescript の `.ls-lint.yml` の `.*:` regex) | — | — | 削除(新規プロジェクトは template から作る,というユーザーの方針) | | (wave 2) | references/code_style.md | Name files by the domain or action, not a role suffix | 既存 linter(ls-lint,有効化が必要) | — | — | 残す(波 2 に記載) | | `ts_no_vague_name` | references/code_style.md | Avoid `manager`, `helper`, `util`, and `common` unless the name is already established locally | 文章のまま | — | — | 残す.`Manager` / `Helper` / `Util` / `Common` を含む識別子は常に誤りとは限らず,静的規則だと編集を止めてしまうため,ユーザーの判断で規則を削除した(ts_no_vague_name / tsx_no_vague_name) | | (oxlint) | references/code_style.md | Use `import type` for type-only imports | 既存 linter(template-typescript の `typescript/consistent-type-imports`(tsc `verbatimModuleSyntax`)) | — | — | 削除 | | (oxlint) | references/code_style.md | Do not create import cycles | 既存 linter(template-typescript の `import/no-cycle`) | — | — | 削除 | | (oxfmt) | references/code_style.md | Let oxfmt define formatting. Do not hand-format around it | 既存 linter(template-typescript の `pnpm run format:check`(oxfmt)) | — | — | 削除 | | — | references/code_style.md | Keep user-facing wording separate from logic, in a dedicated module such as `src/copy/` | 文章のまま | — | — | 残す.文言かどうかとモジュール配置の判断はプロジェクト構成に依存し,構文からも関数単位でも yes/no にできない | | `comment-explains-why` | references/code_style.md | Comments explain why, not what | jev-lint | model-rules/typescript/comment-explains-why/rule.yml | なし(保留) | 残す(ADR-0021) | | `comment-explains-why` | references/code_style.md | Prefer clear types, function names, and module boundaries over explanatory comments | jev-lint(同上) | 同上 | なし | 残す(ADR-0021) | | — | references/code_style.md | Architectural choices, dependency decisions, and external-tool boundary rules belong in ADRs | 文章のまま | — | — | 残す.記録先の方針で,コードに現れない | | `expected-failure-returned-as-value` | references/errors.md | Return expected failures as values (`Result`) | jev-lint | model-rules/typescript/expected-failure-returned-as-value/rule.yml | なし | 残す | | — | references/errors.md | Define the `Result` type once and reuse it | 文章のまま | — | — | 残す.複数ファイルにまたがる重複で,1 関数・1 ファイルの判定にならない | | — | references/errors.md | Make `error` a union of tagged variants when callers branch on the failure category | 文章のまま | — | — | 残す.呼び出し側の分岐は他ファイルにあり,その場で見えない | | `expected-failure-returned-as-value` | references/errors.md | `throw` only for programmer errors and unrecoverable states | jev-lint(上と同じ規則) | 同上 | なし | 残す | | `ts_catch_rethrow_requires_cause` | references/errors.md | Add context when rethrowing or converting: `new Error(message, { cause })` | oxlint `preserve-caught-error`(ast-grep 規則は削除) | — | — | 残す(値への変換と「操作と対象を名指す」は規則が覆わない.後者は既存の `error-message-names-operation`) | | `error-message-names-operation`(既存) | references/errors.md | The message names the operation and subject | jev-lint(既存規則) | model-rules/typescript/error-message-names-operation | 既存 | 残す | | (波 2) | references/errors.md | Do not swallow errors with an empty `catch` | 既存 linter(template-typescript の `no-empty`(`allowEmptyCatch: false`)) | — | — | 一部削除(空ブロックは linter が覆う.コメントやログだけの `catch` も握りつぶしである,という点を残した) | | (oxlint) | references/errors.md | Await or explicitly handle every promise; do not disable `no-floating-promises` / `no-misused-promises` / `await-thenable` | 既存 linter(template-typescript の `typescript/no-floating-promises` / `no-misused-promises` / `await-thenable`) | — | — | 削除 | | `states-modeled-as-discriminated-union` | references/types.md | Model states and kinds as discriminated unions with a tag field, not optional fields or flags | jev-lint | model-rules/typescript/states-modeled-as-discriminated-union/rule.yml | なし | 残す | | (波 2) | references/types.md | Handle a union with an exhaustive `switch` whose `default` assigns `satisfies never` | 既存 linter(template-typescript の `typescript/switch-exhaustiveness-check`) | — | — | 一部削除(網羅性は linter が覆う.`default` で `satisfies never` を代入する形だけ残した) | | — | references/types.md | Represent values with validation or invariants as branded types created by a validating `parse` function | 文章のまま | — | — | 残す.値オブジェクト一般は `agents` 担当の AGENTS.md の規則.ブランドの作り方は 1 関数では判定できず,jev 規則にすると同規則と重複する | | `ts_readonly_property` | references/types.md | Declare properties `readonly` … by default | 文章のまま | — | — | 残す.ユーザーの判断で ast-grep 規則は削除した(「既定」の例外が稀でなく,構文から可変の意図を区別できない).`typescript/prefer-readonly` は template-typescript で別途有効化する予定(この PR では未実施) | | `ts_readonly_array_property` | references/types.md | … and arrays `readonly T[]` by default | 文章のまま | — | — | 残す.ユーザーの判断で ast-grep 規則は削除した(「既定」の例外が稀でなく,構文から可変の意図を区別できない).`typescript/prefer-readonly` は template-typescript で別途有効化する予定(この PR では未実施) | | `ts_readonly_array_property` | references/types.md | Do not expose a mutable raw collection from a domain type | 文章のまま | — | — | 残す.ユーザーの判断で ast-grep 規則は削除した(「既定」の例外が稀でなく,構文から可変の意図を区別できない).`typescript/prefer-readonly` は template-typescript で別途有効化する予定(この PR では未実施) | | `ts_no_unvalidated_json_cast` | references/types.md | Accept external input as `unknown` and parse it once at the boundary | oxlint `typescript/no-unsafe-type-assertion` / `no-unsafe-assignment` / `no-unsafe-return`(ast-grep 規則は削除) | — | — | 残す(環境変数・storage など他の境界,「一度だけ検証」は覆わない) | | `type-assertion-follows-validation` | references/types.md | Do not use `as` casts except immediately after validation | jev-lint | model-rules/typescript/type-assertion-follows-validation/rule.yml | なし | 残す | | (oxlint) | references/types.md | Do not use `any`; use `unknown` and narrow | 既存 linter(template-typescript の `typescript/no-explicit-any`) | — | — | 削除 | | — | references/types.md | Group arguments into a type only when it names a real domain concept | 文章のまま | — | — | 残す.`agents` 担当の AGENTS.md に同じ規則があり,ここで別に判定しない | | `ts_no_other_test_framework` | references/testing.md | Use only `vitest` as test framework; do not add Jest | oxlint `no-restricted-globals` / `no-restricted-imports`(ast-grep 規則は削除) | — | — | 残す(`package.json` への依存追加と「globals を有効にする」設定は覆わない) | | — | references/testing.md | Run tests with `pnpm run test` | 文章のまま | — | — | 残す.実行手順 | | `repeated-cases-use-it-each` | references/testing.md | Use `it.each` for the same behavior across multiple inputs | jev-lint | model-rules/typescript/repeated-cases-use-it-each/rule.yml | なし | 残す | | `mock-only-external-boundaries` | references/testing.md | Prefer fake implementations over mocks. Use `vi.mock` only for external dependencies at module boundaries | jev-lint | model-rules/typescript/mock-only-external-boundaries/rule.yml | なし | 残す | | `inject-time-and-randomness` | references/testing.md | Inject time and randomness as arguments instead of reading `Date.now()` / `Math.random()` inside logic | jev-lint(エントリポイントでの読み取りは正当なので ast-grep にしない) | model-rules/typescript/inject-time-and-randomness/rule.yml | なし | 残す | | `ts_no_home_dir_in_tests` | references/testing.md | Do not touch the real home directory | 文章のまま | — | — | 残す.ユーザーの判断で ast-grep 規則は削除した(`HOME` の退避と復元のための読み取りと区別できない) | | `known-defect-marker-names-removal`(既存) | references/testing.md | Record a reproduced defect with `test.fails` and a comment naming the removal condition; remove the marker in the fixing change | jev-lint(既存規則) | model-rules/typescript/known-defect-marker-names-removal | 既存 | 残す(マーカーを外す手順は規則が覆わない) | | — | references/testing.md | Mutation Testing: use StrykerJS 10.x with the Vitest runner; add dev dependencies only when needed | 文章のまま | — | — | 残す.道具の選択と導入時期の方針 | | — | references/testing.md | Set `"testRunner": "vitest"` in `stryker.config.json` | 文章のまま | — | — | 残す.設定を作る手順.JSON 設定は編集後 hook の走査対象外で,Stryker を使うときだけ関係する | | — | references/testing.md | Scope a run to the changed module (`pnpm exec stryker run --mutate ...`) | 文章のまま | — | — | 残す.実行手順 | | — | references/testing.md | Read survivors in the clear-text output or the HTML report | 文章のまま | — | — | 残す.作業手順 | | — | references/testing.md | Keep `.stryker-tmp/` and `reports/` out of version control | 文章のまま | — | — | 残す.`.gitignore` の内容で,編集後 hook の対象外 | | — | references/testing.md | Unit test: `*.test.ts` next to the module | 文章のまま | — | — | 残す.配置は vitest の `include` 設定で決まり,構文から判定できない | | — | references/testing.md | End-to-end test: under `tests/` | 文章のまま | — | — | 残す.同上 | | — | references/testing.md | Helper function: prefer local helpers when setup is lightweight | 文章のまま | — | — | 残す.好みの方針 | | `mock-only-external-boundaries` | references/testing.md | Fake implementation: prefer explicit fake objects over global mocks | jev-lint(上と同じ規則) | 同上 | なし | 残す | | — | references/tooling.md | Use pnpm only; do not mix in npm or yarn, no competing lock file | 文章のまま | — | — | 残す.`package.json` と lock ファイルの運用で,ソースの構文に現れない | | — | references/tooling.md | Install from the lock with `pnpm install --frozen-lockfile` | 文章のまま | — | — | 残す.実行手順 | | — | references/tooling.md | Add dependencies with `pnpm add` / `pnpm add -D` | 文章のまま | — | — | 残す.実行手順 | | — | references/tooling.md | Do not use `@latest`-style version shortcuts | 文章のまま | — | — | 残す.文書やコマンド履歴が対象で,ソースの構文に現れない | | — | references/tooling.md | Do not edit `pnpm-lock.yaml` manually | 文章のまま | — | — | 残す.編集経路の方針 | | — | references/tooling.md | Do not add a dependency only because it is common | 文章のまま | — | — | 残す.追加の動機の判断 | | — | references/tooling.md | Formatting is oxfmt, linting is oxlint, type checking is `oxlint --type-aware --type-check` | 文章のまま | — | — | 残す.道具の選択の記述 | | — | references/tooling.md | Do not add ESLint, Prettier, or another type checker | 文章のまま | — | — | 残す.道具の選択.`package.json` の依存は構文走査の対象外 | | — | references/tooling.md | Keep the strict `tsconfig.json` options and never loosen them | 文章のまま | — | — | 残す.JSON 設定は編集後 hook の走査対象外(ast-grep の JSON 規則を置いても走らない) | | (knip) | references/tooling.md | Detect unused files, exports, and dependencies with knip | 既存 linter(template-typescript の `pnpm run knip`(`check` にも含まれる)) | — | — | 削除 | | — | references/tooling.md | Store production code in `src/` | 文章のまま | — | — | 残す.配置の方針 | | — | references/tooling.md | Colocate unit tests as `*.test.ts`; e2e tests in `tests/` | 文章のまま | — | — | 残す(testing.md と同じ理由) | | — | references/tooling.md | Enforce layer boundaries with `no-restricted-imports` | 文章のまま | — | — | 残す.層の定義はプロジェクトごとの `.oxlintrc.json` で,共有の規則にできない | | (波 2) | references/tooling.md | Avoid `utils.ts` and `helpers.ts`; name modules by domain or action | 既存 linter(ls-lint,有効化が必要) | — | — | 残す(波 2 に記載) | | — | references/tooling.md | Confirm verification results; run through `package.json` scripts, not the underlying binaries | 文章のまま | — | — | 残す.実行手順(`tsdd` の検証方針) | | — | SKILL.md | Scope: routine edits do not authorize introducing Nix or changing GitHub settings | 文章のまま | — | — | 残す.作業範囲の方針 | | — | SKILL.md | Read only the references relevant to the current task | 文章のまま | — | — | 残す.案内.表の「code_style」行から imports と formatting を除いた | ## 波 2: linter で有効化する規則 テンプレートは変更していない.`no-empty` と `typescript/switch-exhaustiveness-check` は template-typescript で有効になったため表から外した.残る規則を有効化すれば,右端の文章を削除できる. | repo | 設定ファイル | 規則 ID | 置き換える文章 | | --------------------------- | -------------- | ------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | | furedea/template-typescript | `.ls-lint.yml` | `.ts` / `.tsx` の名前に `utils` / `helpers` / `util` / `helper` / `manager` / `common` と役割接尾辞(`formatter` など)を禁じる regex | code_style.md「Name files by the domain or action…」,tooling.md「Avoid `utils.ts` and `helpers.ts`」,code_style.md の「Avoid `manager`…」のうちファイル名の部分 | - 再レビュー対応(この PR の最終): 受け手の名前に依存しない `json()` の型アサーション,`.catch` のコールバック(引数を束縛する場合),再エクスポートと動的 import,追加のフレームワーク名,ジェネレーターの境界を直した.以前の対応:`ts_no_unvalidated_json_cast` は `json()` の受け手を `res` / `response` 系の名前に限り,型付き引数の既定値も対象にした.`ts_catch_rethrow_requires_cause` は `.catch` のコールバックも見る.`ts_no_other_test_framework` は動的 `import()` / `require()` も見る.`repeated-cases-use-it-each` は `describe.each` の表の呼び出しを除く. - ブロックする 3 規則(`ts_` / `tsx_`)の `message` に失敗の理由,`note` に直し方(before / after の 1 行)を書いた(PR #203 の blocking hook が両方を表示する). ## 検証 - `ast-grep test --config agents/hooks/lint/sgconfig.yml --skip-snapshot-tests`: 15 件通過 - `REQUIRE_AST_GREP=1 nix develop --command uv run pytest`: 4864 passed,1 skipped ## 後続(再レビューの上限で保留した指摘) - `repeated-cases-use-it-each`: Vitest の `suite(...)` も `describe` と同じく選ぶ. - `inject-time-and-randomness`: `Date()`(`new` なし)と括弧なしの `new Date` も選ぶ. - `comment-explains-why`: アロー関数・関数式の親が `jsx_expression`,`export_statement`,`assignment_expression`,配列などの場合も subject にする. - `inject-time-and-randomness`: `crypto.getRandomValues(...)` も乱数の読み取りとして選ぶ. - `expected-failure-returned-as-value`,`comment-explains-why`,`inject-time-and-randomness`: オブジェクトプロパティ(`pair`)に束縛した関数も subject にする. - `type-assertion-follows-validation` と `angle-bracket-assertion-follows-validation`: `state` を `located` にする. - `comment-explains-why`: 関数外コメントの subject に隣接コードを渡すため `state` を `located` にする. - `expected-failure-returned-as-value`: `export default () => { throw ... }` のように `export_statement` に直接置かれた関数も subject にする. - `mock-only-external-boundaries`: `vi.spyOn(client, "send")` のように定義元が呼び出しから分からない場合のため,`state` を `located` にして周辺コードを渡す. - `inject-time-and-randomness`: bare な `randomInt(...)` などは import 元を確認せず over-match する(同名ヘルパーにも一致).`state` を `located` にするか criteria の false 側に加える. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: furedea <[email protected]> Co-authored-by: Claude Sonnet 5.5 <[email protected]>
概要
.oxlintrc.jsonのrulesに以下 4 つを追加しました.preserve-caught-errortypescript/no-unsafe-type-assertiontypescript/no-unsafe-assignmenttypescript/no-unsafe-return後ろ 3 つは型情報を使うルールで,
pnpm typecheck(oxlint --type-aware --type-check)で実行されます.置き換える ast-grep ルール
furedea/agent-config の blocking ast-grep ルールのうち,安定して動作させられなかったものを置き換えます.
catch内でcauseを付けずに再 throw する →preserve-caught-errorJSON.parse(t) as Bodyのキャスト →typescript/no-unsafe-type-assertionconst c: Body = JSON.parse(t)の代入 →typescript/no-unsafe-assignmentreturn JSON.parse(t)(戻り値型がBody)→typescript/no-unsafe-returnRefs furedea/agent-config#74
検証
pnpm run check(format:check,lint,typecheck,test,knip,audit)がすべて成功しました.テンプレートコードに新たな指摘はありません.🤖 Generated with Claude Code