feat: Add ESLint complexity rules template to prevent technical debt - #293
Conversation
- 新規作成: eslint/ ディレクトリにテンプレートとドキュメント - complexity-rules.mjs: エクスポート可能な複雑度ルール定義 - README.md: 詳細な使用方法とフェーズ別導入戦略 - eslint.config.mjs を更新して推奨値を適用: - complexity: 10 → 15 (より現実的な循環的複雑度) - max-lines-per-function: 50 → 100行 - max-params: 4 → 5個 - 新規追加: max-lines (500行のファイル長制限) - すべてのルールを "warn" に設定 (Phase 1) - README.md にディレクトリ構造を追加 Source: Elu-co-jp/management_tools Closes #290 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> Co-authored-by: keito4 <keito4@users.noreply.github.com>
📝 WalkthroughWalkthroughIntroduces ESLint complexity rules configuration through a new template system. Updates eslint.config.mjs to use phase-1 warnings with relaxed thresholds, adds a complexity-rules.mjs template file, provides comprehensive documentation in eslint/README.md, and updates the main README.md directory listing. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Poem
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches
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 |
There was a problem hiding this comment.
Actionable comments posted: 2
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
README.mdeslint.config.mjseslint/README.mdeslint/complexity-rules.mjs
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: claude-review
🔇 Additional comments (7)
README.md (1)
20-20: LGTM! Well-integrated documentation.The eslint/ directory entry is properly formatted and consistent with other directory listings. The description clearly conveys the purpose and links to detailed usage guidelines.
eslint/README.md (2)
1-14: Excellent documentation structure.The overview clearly articulates the purpose and scope of complexity rules. Well-organized introduction.
51-79: Clear phased implementation strategy.The two-phase approach (warn → error) provides a pragmatic path for adoption without disrupting existing workflows. Well-documented with concrete examples.
eslint.config.mjs (2)
24-45: Phase 1 complexity rules properly implemented.The complexity rules are correctly configured with warning-level enforcement and sensible thresholds. The inline comment effectively directs users to the comprehensive documentation.
Note: There's a minor inconsistency where
max-nested-callbacks(line 45) is configured here but not included in thecomplexity-rules.mjstemplate or documented ineslint/README.md. Consider aligning this across all three files.
48-55: Appropriate test file relaxations.Disabling
max-lines-per-functionand increasingmax-nested-callbacksfor test files is a sensible exception, as test code often requires different complexity patterns.eslint/complexity-rules.mjs (2)
1-12: Comprehensive JSDoc documentation.The header clearly explains the purpose, source attribution, and phased implementation strategy. Well-structured template introduction.
14-72: Well-documented complexity rules with clear rationale.Each rule includes helpful JSDoc comments explaining its purpose and recommended values. The structure makes it easy for teams to understand and customize the rules for their needs.
Minor note: Consider whether
max-nested-callbacks(present ineslint.config.mjsat line 45) should be included in this template for consistency.
| /** | ||
| * Usage Example: | ||
| * | ||
| * import { complexityRules } from './eslint/complexity-rules.mjs'; | ||
| * | ||
| * export default [ | ||
| * { | ||
| * files: ['**\/*.{js,jsx,ts,tsx}'], | ||
| * rules: { | ||
| * ...complexityRules, | ||
| * // Your other rules | ||
| * }, | ||
| * }, | ||
| * ]; | ||
| */ |
There was a problem hiding this comment.
Fix the escaped backslash in the glob pattern.
Line 81 contains an incorrectly escaped forward slash in the glob pattern. The backslash before the forward slash is unnecessary and will cause the pattern to fail matching files correctly.
🔎 Proposed fix
* export default [
* {
- * files: ['**\/*.{js,jsx,ts,tsx}'],
+ * files: ['**/*.{js,jsx,ts,tsx}'],
* rules: {
* ...complexityRules,📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| /** | |
| * Usage Example: | |
| * | |
| * import { complexityRules } from './eslint/complexity-rules.mjs'; | |
| * | |
| * export default [ | |
| * { | |
| * files: ['**\/*.{js,jsx,ts,tsx}'], | |
| * rules: { | |
| * ...complexityRules, | |
| * // Your other rules | |
| * }, | |
| * }, | |
| * ]; | |
| */ | |
| /** | |
| * Usage Example: | |
| * | |
| * import { complexityRules } from './eslint/complexity-rules.mjs'; | |
| * | |
| * export default [ | |
| * { | |
| * files: ['**/*.{js,jsx,ts,tsx}'], | |
| * rules: { | |
| * ...complexityRules, | |
| * // Your other rules | |
| * }, | |
| * }, | |
| * ]; | |
| */ |
🤖 Prompt for AI Agents
In eslint/complexity-rules.mjs around lines 74 to 88, the usage example's glob
pattern on line 81 has an unnecessary escaped forward slash ("\\/") which
prevents correct file matching; edit the pattern to remove the backslash so it
reads '**/*.{js,jsx,ts,tsx}' (i.e., change ['**\\/*.{js,jsx,ts,tsx}'] to
['**/*.{js,jsx,ts,tsx}']) and save.
| ## Rules Reference | ||
|
|
||
| | Rule | Limit | Purpose | | ||
| | ------------------------ | ----- | --------------------------- | | ||
| | `complexity` | 15 | Cyclomatic complexity limit | | ||
| | `max-lines-per-function` | 100 | Function length limit | | ||
| | `max-lines` | 500 | File length limit | | ||
| | `max-depth` | 4 | Nesting depth limit | | ||
| | `max-params` | 5 | Function parameter limit | |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
# Check for max-nested-callbacks references across the repository
rg -n 'max-nested-callbacks' --type=js --type=md -C2Repository: keito4/config
Length of output: 39
🏁 Script executed:
# Find and examine eslint.config.mjs
fd -t f 'eslint\.config\.mjs' -x cat -n {}Repository: keito4/config
Length of output: 1824
🏁 Script executed:
# Check the README.md file
fd -t f 'README\.md' -path '*/eslint/*' -x cat -n {}Repository: keito4/config
Length of output: 225
🏁 Script executed:
# Find and examine the README in the eslint directory
find . -name README.md -path '*/eslint/*' -exec cat -n {} \;Repository: keito4/config
Length of output: 4085
🏁 Script executed:
# Broader search for README.md files
find . -name README.md | head -10Repository: keito4/config
Length of output: 308
Add max-nested-callbacks to the Rules Reference table.
The max-nested-callbacks rule is configured in eslint.config.mjs (line 45: limit 3, line 53: limit 5 for test files) but missing from the README's Rules Reference table. Add it for completeness:
| Rule | Limit | Purpose |
|---|---|---|
max-nested-callbacks |
3 | Callback nesting limit |
🤖 Prompt for AI Agents
In eslint/README.md around lines 41 to 49, the Rules Reference table is missing
the max-nested-callbacks entry; update the table by adding a row for
`max-nested-callbacks` with limit `3` and purpose `Callback nesting limit` so
the README matches eslint.config.mjs (note tests use limit 5).
Pull Request Review - PR #293概要ESLint複雑度ルールのテンプレート追加は、技術的負債の予防という重要な目的を果たす良い取り組みです。全体的な実装は適切ですが、いくつかの改善点があります。 ✅ 良い点1. 段階的導入戦略
2. ドキュメント品質
3. 適切な基準値
|
|
🎉 This PR is included in version 1.43.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Summary
Issue #290 で提案されたESLint複雑度ルールのテンプレートを追加しました。これにより、技術的負債の蓄積を防ぎ、コード品質を維持できます。
Changes
1. 新規ディレクトリ:
eslint/complexity-rules.mjs: エクスポート可能な複雑度ルール定義README.md: 包括的なドキュメント2.
eslint.config.mjsの更新complexityerror, 10warn, 15max-lines-per-functionwarn, 50warn, 100max-paramswarn, 4warn, 5max-lineswarn, 5003.
README.mdの更新ディレクトリ構造に
eslint/セクションを追加。Benefits
Source
Source: Elu-co-jp/management_tools
Closes #290
🤖 Generated with Claude Code
Summary by CodeRabbit
Release Notes
New Features
Documentation
Chores
✏️ Tip: You can customize this high-level summary in your review settings.