TDD Guard can optionally check code quality during the refactoring phase (when tests are green) using ESLint. When issues are detected, the coding agent will be prompted to fix them.
During the TDD green phase, the coding agent may:
- Clean up implementation code
- Extract methods or constants
- Improve naming
- Remove duplication
The refactoring support helps by:
- Running ESLint automatically after file modifications
- Detecting code quality issues
- Prompting the coding agent to fix any issues found
-
Install ESLint in your project:
npm install --save-dev eslint@latest
-
Enable linting by setting the environment variable:
LINTER_TYPE=eslint
Note: Currently only ESLint is supported. Additional linters may be added in the future.
-
Configure the PostToolUse hook
You can configure this hook either through the interactive
/hookscommand or by manually editing your settings file. See Settings File Locations to choose the appropriate location. Use the same location as your PreToolUse hook.- Type
/hooksin Claude Code - Select
PostToolUse - After tool execution - Choose
+ Add new matcher... - Enter:
Write|Edit|MultiEdit - Select
+ Add new hook... - Enter command:
tdd-guard - Choose where to save
Add to your chosen settings file:
{ "hooks": { "PostToolUse": [ { "matcher": "Write|Edit|MultiEdit", "hooks": [ { "type": "command", "command": "tdd-guard" } ] } ] } } - Type
When enabled:
- After any file modification (Edit, MultiEdit, Write)
- TDD Guard runs ESLint on modified files
- If issues are found, the coding agent receives a notification
- The agent will then fix the identified issues
Without LINTER_TYPE=eslint, TDD Guard skips all linting operations.
Tip: Configure ESLint with complexity rules (e.g., complexity, max-depth) and the SonarJS plugin to encourage meaningful refactoring.
These rules help identify code that could benefit from simplification during the green phase.
For effective refactoring support, consider adding these rules to your .eslintrc.js:
module.exports = {
rules: {
complexity: ['warn', 10],
'max-depth': ['warn', 4],
'max-lines-per-function': ['warn', 50],
'max-nested-callbacks': ['warn', 3],
'max-params': ['warn', 4],
},
}- Verify ESLint is installed:
npm list eslint - Check that
LINTER_TYPE=eslintis set in your.envfile - Ensure the PostToolUse hook is configured
- Restart your Claude session after making changes