Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ It includes settings for various tools, such as the shell (Zsh), Git, npm, and V
- `.github/`: GitHub configuration including workflows for CI/CD, security scanning, and release automation. The `templates/` subdirectory contains reusable workflow templates for unified CI with coverage reporting and monorepo releases with change detection.
- `brew/`: Contains Brewfiles for different operating systems (Linux, macOS) and dependency configurations, including lock files for reproducible package installations. Supports categorized package management and dependency analysis.
- `credentials/`: Contains templates and scripts for secure credential management using 1Password CLI integration.
- `eslint/`: Contains recommended ESLint complexity rules template and documentation to prevent technical debt accumulation. See [eslint/README.md](eslint/README.md) for usage guidelines.
- `issues/`: Templates and helper notes for managing known issues and troubleshooting steps.
- `dot/`: Directory for dotfiles and configuration files that are typically placed in the home directory, including Zsh configuration with comprehensive aliases, functions, and environment setup.
- `git/`: Contains Git configuration files including gitconfig, gitignore, commitlint configuration with i18n support, and modular configuration files in the `gitconfig.d/` subdirectory. See [git/README.md](git/README.md) for details.
Expand Down
28 changes: 22 additions & 6 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,28 @@ export default [
rules: {
'no-console': 'off',
'no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
// Complexity rules
complexity: ['error', { max: 10 }],
'max-depth': ['error', 4],
'max-nested-callbacks': ['error', 3],
'max-lines-per-function': ['warn', { max: 50, skipBlankLines: true, skipComments: true }],
'max-params': ['warn', 4],
// Complexity rules (Phase 1: warnings to prevent new technical debt)
// See eslint/README.md for detailed documentation
complexity: ['warn', { max: 15 }],
'max-lines-per-function': [
'warn',
{
max: 100,
skipBlankLines: true,
skipComments: true,
},
],
'max-lines': [
'warn',
{
max: 500,
skipBlankLines: true,
skipComments: true,
},
],
'max-depth': ['warn', 4],
'max-params': ['warn', 5],
'max-nested-callbacks': ['warn', 3],
},
},
// Relaxed rules for test files
Expand Down
136 changes: 136 additions & 0 deletions eslint/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
# ESLint Complexity Rules

This directory contains recommended ESLint complexity rules to prevent technical debt accumulation.

## Overview

Code complexity rules help maintain code quality by enforcing limits on:

- Cyclomatic complexity
- Function length
- File length
- Nesting depth
- Function parameters

## Files

- `complexity-rules.mjs`: Exportable complexity rules configuration

## Usage

### Import in ESLint Config (Flat Config)

```javascript
import { complexityRules } from './eslint/complexity-rules.mjs';

export default [
{
files: ['**/*.{js,jsx,ts,tsx}'],
rules: {
...complexityRules,
// Your other rules
},
},
];
```

### Copy Rules Directly

Copy the rules object from `complexity-rules.mjs` into your existing ESLint configuration.

## 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 |
Comment on lines +41 to +49

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


## Implementation Strategy

### Phase 1: Warning Mode (Current)

Set all rules to `"warn"` to detect issues without breaking builds:

```javascript
"complexity": ["warn", { "max": 15 }]
```

This allows you to:

- Identify existing violations
- Prevent new technical debt
- Gradually refactor problematic code

### Phase 2: Error Mode (Future)

Once the codebase is compliant, upgrade to `"error"`:

```javascript
"complexity": ["error", { "max": 15 }]
```

This will:

- Block CI/CD pipeline on violations
- Enforce strict compliance
- Maintain code quality standards

## Test File Exceptions

Consider relaxing rules for test files:

```javascript
{
files: ['**/*.test.js', '**/*.spec.js', '**/test/**/*.js'],
rules: {
'max-lines-per-function': 'off',
'complexity': 'off',
},
}
```

## Customization

Adjust limits based on your project needs:

```javascript
export const complexityRules = {
complexity: ['warn', { max: 10 }], // Stricter
'max-lines-per-function': [
'warn',
{
max: 150, // More lenient
skipBlankLines: true,
skipComments: true,
},
],
};
```

## CI Integration

Add ESLint complexity checks to your CI pipeline:

```yaml
- name: Run ESLint
run: npm run lint
```

## Source

These rules were discovered from `Elu-co-jp/management_tools` repository and recommended for organization-wide adoption.

## Related Files

- `/eslint.config.mjs`: Main ESLint configuration for this repository
- `.github/workflows/templates/unified-ci.yml`: CI workflow template with linting

## Benefits

- **Prevents technical debt**: Catches complex code early
- **Improves readability**: Enforces consistent code structure
- **Maintains quality**: Automated enforcement in CI/CD
- **Gradual adoption**: Warn-first approach allows incremental improvements
88 changes: 88 additions & 0 deletions eslint/complexity-rules.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/**
* ESLint Complexity Rules Template
*
* These rules help prevent technical debt accumulation by enforcing
* code complexity limits. Use this as a reference for your projects.
*
* Source: Discovered from Elu-co-jp/management_tools
*
* Implementation Strategy:
* - Phase 1: Set rules to "warn" to detect issues without breaking builds
* - Phase 2: Upgrade to "error" once codebase is compliant
*/

export const complexityRules = {
/**
* Cyclomatic Complexity
* Limits the complexity of functions by counting the number of linearly
* independent paths through the code.
*
* Recommended: 15 (warn), stricter: 10 (error)
*/
complexity: ['warn', { max: 15 }],

/**
* Function Length
* Limits the number of lines in a function to maintain readability.
*
* Recommended: 100 lines (warn)
* Blank lines and comments are not counted.
*/
'max-lines-per-function': [
'warn',
{
max: 100,
skipBlankLines: true,
skipComments: true,
},
],

/**
* File Length
* Limits the number of lines in a file to maintain focus and cohesion.
*
* Recommended: 500 lines (warn)
* Blank lines and comments are not counted.
*/
'max-lines': [
'warn',
{
max: 500,
skipBlankLines: true,
skipComments: true,
},
],

/**
* Nesting Depth
* Limits the depth of nested blocks to improve readability.
*
* Recommended: 4 levels (warn)
*/
'max-depth': ['warn', 4],

/**
* Function Parameters
* Limits the number of parameters a function can accept.
*
* Recommended: 5 parameters (warn)
* Consider using an options object for more parameters.
*/
'max-params': ['warn', 5],
};

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

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.