fix: severity の変換を eslint.config.js から出して、テストで守る - #71
Conversation
Closes #48 eslint.config.js はロジックを持っている。raise 変換がプリセットの warn を error に 上げる —— 「CI で warn は無価値」だから。そしてそれを守るものが何も無かった。 raise の中身を entry => entry にすると lint / lint:overrides / test すべて exit 0 の まま、実際には 14 件が error -> warn に落ちる。全部 security プラグインで、 detect-child-process / detect-eval-with-expression / detect-non-literal-fs-filename など。警告は CI を落とさず lint の出力を読むものも無いので、security の指摘 14 件が 黙って参考情報に格下げされても誰も気づかない。 これは型検査では捕まらない。raise は型としては正しいまま、意味だけが変わる。 raise / enforced を eslint.severity.js に出した。eslint.config.js が直接 import する ので TypeScript にはできない(ESLint はあのファイルをそのまま読む。.ts にすると 1 つの 関数のために jiti をローダに入れることになる)。型は eslint.severity.d.ts で与えている —— @ts-expect-error で黙らせない。 決め手のテストはフィクスチャではなく解決後の実 config に対して「プリセットのブロックに warn が 1 つも残っていない」と主張する。フィクスチャは壊れた変換とも辻褄が合うため。 eslint.config.d.ts はその import のために置いたもので、default を unknown[] と宣言して いる —— 制御できない形を構造的に主張しないため。読む側が絞る。 挙動保存: 旧 config と新 config の解決結果を全キー比較(497 キー、ルールの severity と ブロックの全キー)—— 差分 0。 break-verify: 4 変異とも撃墜(恒等関数 / "warn" だけ見て数値 1 を見落とす / オプションを捨てて "error" を返す / off まで上げてしまう)。 #48 は当初「型検査されていない 3 ファイル」だったが、2 つは #56/#59/#62 で解決済みで、 残る 1 つについては現実的な設定ミス 7 種を仕込んで測ったところ全部が既存のゲートに 捕まった(うちルール名の綴り違いは yarn lint が素通りさせ、#67 の lint:overrides だけが 捕まえる)。型検査を足すには eslint-plugin-security の declare module シムが要り、それは 実質 any なので安全を足さない。issue を実態に合わせて書き換えたうえで閉じる。 全ゲートを終了コードで確認: format:check 0 / lint 0 / typecheck 0 / test 0 (537 pass) / typecheck:summary 0(床 3 つとも維持)/ lint:overrides 0。 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GTPpB2eHQ9eovAs6QRNsTH
Reviewer's GuideESLint の severity 昇格処理を eslint.config.js からテスト可能な plain-JS モジュールへ分離し、型宣言を添えて、warn の文字列・数値形式を error に変換しつつオプションや off を保持する契約をユニットテストと実 config の検証で保護しています。 Flow diagram for ESLint rule severity conversionflowchart TD
Entry[Rule entry] --> Array{Array with options?}
Array -->|yes| ReadArray[Read first severity]
Array -->|no| ReadValue[Read entry severity]
ReadArray --> Warning{warn or numeric 1?}
ReadValue --> Warning
Warning -->|yes| Raise[Return error and preserve options]
Warning -->|no| Keep[Return entry unchanged]
Raise --> Result[Converted rule entry]
Keep --> Result
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
Warning Review limit reachedNext included review available in 48 minutes. View limit detailsLimit details: You’ve used the included review currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (5)
Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthroughThe PR extracts ESLint severity enforcement into a separate JavaScript module, adds declarations for the module and config, and adds unit and integration tests for warn-to-error conversion. ChangesESLint severity enforcement
Estimated code review effort: 3 (Moderate) | ~20 minutes Merge Risk: ⚪ Minimal · up to This localized ESLint configuration change preserves the intended severity behavior and adds tests around it; no actionable merge-blocking risk remains after normal checks and review. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Full details: Docstring CoverageExplanation No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 5 files. ✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
CI が赤かった件 — このブランチのせいではありませんでした
このブランチはその 2 ファイルを触っていません(差分は 起きていたこと:
手元でその合成を再現したところ、 副次的な確認になりますが、#68 のラチェットは意図どおり働いています。 ファイルが天井を越えて伸びたことを実際に検出し、直すまで main を赤にしていました。ラチェットが「実行不能なノイズになって最初にぶつかった人に消される」のではないか、というのは #67 のレビューで出た懸念でしたが、ここでは越えた本人が同じ日に天井を上げて片付いています。 main 取り込み後、全ゲートを終了コードで確認: |
Summary
Closes #48。issue は測り直して書き換えたうえで閉じます —— 当初の記述(型検査されていない 3 ファイル)は、測ったら実態と違っていました。
元の #48 が言っていたことは、もう問題ではありません
3 ファイルのうち 2 つは #56 / #59 / #62 で解決済みです。残る
eslint.config.jsについて、現実的な設定ミス 7 種を実際に仕込んで何が捕まえるか測りました:yarn lintyarn lint:overridesrules→ruleの綴り違いwarn→warningfiles→fileの綴り違いmax: "600")7 種すべて既存のゲートが捕まえます。ルール名の綴り違いだけ
yarn lintが素通りさせ、#67 で入ったlint:overridesが捕まえます。型検査を足すにはeslint-plugin-securityのdeclare moduleシムが要り、それは実質anyなので安全を足しません。測っている最中に、本当の穴が出ました
eslint.config.jsはロジックを持っています。raise変換がプリセットのwarnをerrorに上げます —— 「CI で warn は無価値」だから。そしてそれを守るものが何もありませんでした。raiseの中身をentry => entryにすると:全部緑のまま、実際には 14 件が error → warn に落ちます。全部 security プラグインです:
警告は CI を落とさず、lint の出力を読むものはありません。security の指摘 14 件が黙って参考情報に格下げされても誰も気づかない状態でした。型検査では捕まりません ——
raiseは型としては正しいまま、意味だけが変わります。Items to Confirm / Review
eslint.severity.jsが.jsであること。eslint.config.jsが直接 import し、ESLint はあのファイルをそのまま読むので、.tsにすると 1 つの関数のためにjitiをローダに入れることになります。型はeslint.severity.d.tsで与えています(@ts-expect-errorでは黙らせていません)。eslint.config.d.tsがdefaultをunknown[]と宣言していること。 構造的な型を書くのは、このリポジトリが制御できない形を主張することになります。読む側が絞る方針です(scripts/overrides-report.tsが実際にそうしていて、読めないブロックは報告します)。warnが 1 つも残っていない」を直接主張しています。per-file の DEBT ブロックは意図的にwarnなので除外しています。挙動保存の証明
旧 config と新 config の解決結果を全キー比較 —— ルールの severity と各ブロックの全キー、497 キーで差分 0。
break-verify
4 変異すべて撃墜:
entry => entry(元の穴そのもの)"warn"だけ見て数値1を見落とす"error"を返すoffまで上げてしまうゲート
終了コードで確認:
format:check0 /lint0 /typecheck0 /test0(537 pass)/typecheck:summary0(床 3 つとも維持)/lint:overrides0。User Prompt
Summary by Sourcery
Extract and test the ESLint severity policy so preset warnings cannot silently bypass CI enforcement.
Bug Fixes:
Enhancements:
Tests:
Summary by CodeRabbit
New Features
Bug Fixes
Tests