Skip to content

feat: Add ESLint complexity rules template to prevent technical debt - #293

Merged
keito4 merged 1 commit into
mainfrom
claude/issue-290-20260102-1101
Jan 3, 2026
Merged

feat: Add ESLint complexity rules template to prevent technical debt#293
keito4 merged 1 commit into
mainfrom
claude/issue-290-20260102-1101

Conversation

@keito4

@keito4 keito4 commented Jan 2, 2026

Copy link
Copy Markdown
Owner

Summary

Issue #290 で提案されたESLint複雑度ルールのテンプレートを追加しました。これにより、技術的負債の蓄積を防ぎ、コード品質を維持できます。

Changes

1. 新規ディレクトリ: eslint/

  • complexity-rules.mjs: エクスポート可能な複雑度ルール定義

    • 5つの主要な複雑度ルール(complexity, max-lines-per-function, max-lines, max-depth, max-params)
    • JSDocによる詳細なドキュメント
    • 使用例付き
  • README.md: 包括的なドキュメント

    • ルールの目的と使用方法
    • Phase 1 (warn) → Phase 2 (error) の段階的導入戦略
    • CI統合ガイド
    • カスタマイズ例

2. eslint.config.mjs の更新

ルール 変更前 変更後 理由
complexity error, 10 warn, 15 より現実的な値に緩和
max-lines-per-function warn, 50 warn, 100 実用的な長さに調整
max-params warn, 4 warn, 5 柔軟性を向上
max-lines - warn, 500 ファイル長制限を追加

3. README.md の更新

ディレクトリ構造に eslint/ セクションを追加。

Benefits

  • ✅ 技術的負債の早期検出
  • ✅ コードの可読性とメンテナンス性の向上
  • ✅ 段階的な導入アプローチ(warn → error)
  • ✅ 組織全体で再利用可能なテンプレート

Source

Source: Elu-co-jp/management_tools

Closes #290


🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • New Features

    • Added a reusable ESLint complexity rules template for consistent code standards across projects.
  • Documentation

    • Added comprehensive documentation for ESLint complexity rules, including usage guidelines and configuration examples.
  • Chores

    • Updated ESLint configuration to enforce complexity rules as warnings rather than strict errors, with relaxed thresholds to align with a phased enforcement approach.

✏️ Tip: You can customize this high-level summary in your review settings.

- 新規作成: 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>
@coderabbitai

coderabbitai Bot commented Jan 2, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Introduces 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

Cohort / File(s) Summary
Documentation & Structure
README.md
Added new entry under top-level directory listings for eslint/ with description of complexity rules template and link to usage guidelines.
ESLint Configuration
eslint.config.mjs
Transitioned from strict error-level complexity rules to phase-1 warning-based approach with relaxed thresholds: complexity max 15 (warn), max-lines-per-function 100 (warn), added max-lines 500 (warn), adjusted max-depth, max-params, and max-nested-callbacks to warning levels while preserving test-file exceptions.
Complexity Rules Template & Documentation
eslint/complexity-rules.mjs, eslint/README.md
Introduced new template file exporting complexityRules constant with five ESLint complexity rules; added comprehensive README documenting purpose, usage examples, rules reference, two-phase implementation strategy, customization, CI integration, and attribution.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Poem

🐰 Hop and rejoice, the rules now clear,
No warnings shall we ever fear,
With thresholds high, the complexity tamed,
Phase one is here, phase two's proclaimed!
Let code flow cleaner, developers cheer! 🎉

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding an ESLint complexity rules template to prevent technical debt, which is the primary focus of all modifications.
Linked Issues check ✅ Passed The PR fully implements all coding requirements from issue #290: exports complexityRules constant with all five specified rules (complexity, max-lines-per-function, max-lines, max-depth, max-params) at correct warn levels and thresholds.
Out of Scope Changes check ✅ Passed All changes directly support the linked issue objectives: complexity rules template creation, configuration updates, documentation, and README addition are all in-scope deliverables.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai 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.

Actionable comments posted: 2

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 32cdfaf and 63381a4.

📒 Files selected for processing (4)
  • README.md
  • eslint.config.mjs
  • eslint/README.md
  • eslint/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 the complexity-rules.mjs template or documented in eslint/README.md. Consider aligning this across all three files.


48-55: Appropriate test file relaxations.

Disabling max-lines-per-function and increasing max-nested-callbacks for 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 in eslint.config.mjs at line 45) should be included in this template for consistency.

Comment on lines +74 to +88
/**
* Usage Example:
*
* import { complexityRules } from './eslint/complexity-rules.mjs';
*
* export default [
* {
* files: ['**\/*.{js,jsx,ts,tsx}'],
* rules: {
* ...complexityRules,
* // Your other rules
* },
* },
* ];
*/

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

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.

Suggested change
/**
* 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.

Comment thread eslint/README.md
Comment on lines +41 to +49
## 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 |

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

# Check for max-nested-callbacks references across the repository
rg -n 'max-nested-callbacks' --type=js --type=md -C2

Repository: 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 -10

Repository: 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).

@claude

claude Bot commented Jan 2, 2026

Copy link
Copy Markdown
Contributor

Pull Request Review - PR #293

概要

ESLint複雑度ルールのテンプレート追加は、技術的負債の予防という重要な目的を果たす良い取り組みです。全体的な実装は適切ですが、いくつかの改善点があります。


✅ 良い点

1. 段階的導入戦略

  • Phase 1 (warn) → Phase 2 (error) のアプローチは実用的で、既存コードへの影響を最小限に抑えます
  • テストファイルへの例外設定(eslint.config.mjs:50-55)が適切です

2. ドキュメント品質

  • eslint/README.md は包括的で、使用例、カスタマイズ方法、CI統合まで網羅しています
  • JSDocコメント(complexity-rules.mjs)が各ルールの目的を明確に説明しています

3. 適切な基準値

  • complexity: 15, max-lines-per-function: 100 など、現実的な値が設定されています
  • 厳しすぎず緩すぎない、バランスの取れた設定です

⚠️ 改善が必要な点

1. CRITICAL: ルールの不一致 🔴

問題: eslint/complexity-rules.mjs で定義されたルールと eslint.config.mjs の実装に不一致があります。

// eslint/complexity-rules.mjs には含まれているが、
// complexity-rules.mjs にはない:
'max-nested-callbacks': ['warn', 3],  // eslint.config.mjs:45

影響:

  • ユーザーが complexityRules をインポートしても max-nested-callbacks が適用されない
  • テンプレートとしての一貫性が損なわれる

推奨対応:
eslint/complexity-rules.mjs に以下を追加:

export const complexityRules = {
  complexity: ['warn', { max: 15 }],
  'max-lines-per-function': [...],
  'max-lines': [...],
  'max-depth': ['warn', 4],
  'max-params': ['warn', 5],
  'max-nested-callbacks': ['warn', 3],  // ← 追加
};

ファイル: eslint/complexity-rules.mjs:71


2. テストカバレッジの欠如 🟡

問題: CLAUDE.md で定義された「70%+ 行カバレッジ」要件を満たすテストがありません。

既存の test/eslint-config.test.js には複雑度ルールのテストが含まれていません。

推奨対応:
test/eslint-config.test.js に以下のテストを追加:

describe('Complexity rules', () => {
  test('should configure complexity rule as warning', () => {
    expect(configContent).toContain("complexity: ['warn', { max: 15 }]");
  });

  test('should configure max-lines-per-function', () => {
    expect(configContent).toContain("'max-lines-per-function'");
    expect(configContent).toContain('max: 100');
  });

  test('should configure max-lines', () => {
    expect(configContent).toContain("'max-lines'");
    expect(configContent).toContain('max: 500');
  });

  test('should configure max-depth', () => {
    expect(configContent).toContain("'max-depth': ['warn', 4]");
  });

  test('should configure max-params', () => {
    expect(configContent).toContain("'max-params': ['warn', 5]");
  });

  test('should configure max-nested-callbacks', () => {
    expect(configContent).toContain("'max-nested-callbacks'");
  });

  test('should relax complexity rules for test files', () => {
    expect(configContent).toContain("'max-lines-per-function': 'off'");
  });
});

さらに、complexity-rules.mjs の輸出が正しく機能することを検証:

// test/complexity-rules.test.js (新規)
describe('Complexity Rules Module', () => {
  test('should export complexityRules object', async () => {
    const { complexityRules } = await import('../eslint/complexity-rules.mjs');
    expect(complexityRules).toBeDefined();
    expect(typeof complexityRules).toBe('object');
  });

  test('should include all required rules', async () => {
    const { complexityRules } = await import('../eslint/complexity-rules.mjs');
    expect(complexityRules).toHaveProperty('complexity');
    expect(complexityRules).toHaveProperty('max-lines-per-function');
    expect(complexityRules).toHaveProperty('max-lines');
    expect(complexityRules).toHaveProperty('max-depth');
    expect(complexityRules).toHaveProperty('max-params');
  });
});

3. マイナー: 使用例のエスケープミス 🟡

問題: complexity-rules.mjs:81 の使用例にエスケープエラーがあります。

// 現在(誤):
files: ['**\/*.{js,jsx,ts,tsx}'],

// 正しい:
files: ['**/*.{js,jsx,ts,tsx}'],

ファイル: eslint/complexity-rules.mjs:81


4. ドキュメント改善の提案 🔵

eslint/README.md の改善案:

4.1 実際の違反例を追加

開発者が理解しやすいよう、具体的な違反例を追加:

## Common Violations Examples

### Cyclomatic Complexity (complexity: 15)**Bad** (complexity: 18):
\`\`\`javascript
function processOrder(order) {
  if (order.type === 'express') {
    if (order.value > 100) {
      if (order.user.isPremium) {
        // ... 深いネスト
      }
    }
  }
  // 多数の分岐...
}
\`\`\`**Good**: 早期リターンや関数分割で複雑度を削減

4.2 段階的な適用手順を明確化

## Migration Guide

1. **Week 1-2**: Add rules as "warn", run lint to identify violations
2. **Week 3-4**: Refactor top 10 most complex functions
3. **Month 2**: Gradually reduce limits or upgrade to "error"
4. **Ongoing**: Monitor in CI/CD pipeline

🔒 セキュリティ

  • ✅ セキュリティ上の懸念なし
  • ✅ 機密情報の漏洩なし
  • ✅ 設定ファイルのみで実行コードなし

⚡ パフォーマンス

  • ✅ パフォーマンスへの影響は最小限(静的解析のみ)
  • ✅ CI実行時間への影響は無視できるレベル

📝 コミット規約


🎯 優先度付き推奨アクション

必須(マージ前):

  1. max-nested-callbackscomplexity-rules.mjs に追加
  2. テストカバレッジを追加(最低でも eslint-config.test.js に複雑度ルールのテスト)

推奨(マージ後でも可):

  1. 🔵 使用例のエスケープ修正
  2. 🔵 ドキュメントに違反例と移行ガイド追加

総合評価

評価: ⭐⭐⭐⭐☆ (4/5)

技術的負債予防という重要な目的を果たす良いPRですが、ルールの不一致とテストカバレッジ不足という2つのクリティカルな問題があります。これらを修正すれば、組織全体で再利用可能な高品質なテンプレートになります。

CLAUDE.md の品質基準(TDD, 70%+ カバレッジ)を満たすため、上記の必須アクションの対応をお願いします。


🤖 Review generated by Claude Code

@keito4
keito4 merged commit b378726 into main Jan 3, 2026
18 checks passed
@github-actions

github-actions Bot commented Jan 4, 2026

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 1.43.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@github-actions github-actions Bot added the released リリース済み label Jan 4, 2026
@keito4
keito4 deleted the claude/issue-290-20260102-1101 branch January 29, 2026 00:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released リリース済み

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Add ESLint complexity rules to prevent technical debt

1 participant