|
| 1 | +# Plan: 066 |
| 2 | + |
| 3 | +Captured: 2025-09-17T00:22:54.261Z |
| 4 | + |
| 5 | +## Plan: Make cc-track Lint-Agnostic with Built-in Support for Biome and ESLint |
| 6 | + |
| 7 | +### Investigation Results: Biome-Specific Hardcoded Assumptions |
| 8 | + |
| 9 | +After investigating the codebase, I found that while the configuration system appears to support any lint command, there are indeed several hardcoded assumptions specific to Biome that need to be fixed: |
| 10 | + |
| 11 | +### Issues Found: |
| 12 | + |
| 13 | +1. **`src/lib/validation.ts` - runBiomeCheck function (lines 91-130)**: |
| 14 | + - Function name itself is "runBiomeCheck" (should be generic like "runLintCheck") |
| 15 | + - Line 98: Hardcoded `bunx biome check --write` for auto-formatting |
| 16 | + - Line 109: Adds `--error-on-warnings` flag specifically for Biome |
| 17 | + - Line 120: Parses Biome-specific output format "diagnostic" |
| 18 | + - Variable names reference "biome" throughout |
| 19 | + |
| 20 | +2. **`src/hooks/edit-validation.ts` - runBiomeCheck function (lines 178-219)**: |
| 21 | + - Function name is "runBiomeCheck" (should be generic) |
| 22 | + - Line 192: Adds `--reporter=compact` flag specifically for Biome |
| 23 | + - Line 208-213: Parses Biome-specific compact output format |
| 24 | + |
| 25 | +3. **`src/commands/prepare-completion.ts` (lines 281-293)**: |
| 26 | + - Line 283: Messages reference "Biome issues" specifically |
| 27 | + - Line 292: Hardcoded advice to use `bunx biome check --write` |
| 28 | + |
| 29 | +4. **Variable/property naming throughout**: |
| 30 | + - `ValidationResult` interface has property called "biome" |
| 31 | + - Config properties use "biome" in variable names |
| 32 | + |
| 33 | +### Detailed Fix Plan: |
| 34 | + |
| 35 | +1. **Update configuration structure** to support tool detection: |
| 36 | + ```typescript |
| 37 | + // In track.config.json |
| 38 | + "lint": { |
| 39 | + "enabled": true, |
| 40 | + "tool": "biome", // "biome" | "eslint" | "custom" |
| 41 | + "command": "bunx biome check", |
| 42 | + "autoFixCommand": "bunx biome check --write", // optional |
| 43 | + "customParser": "path/to/parser.js" // only needed for tool: "custom" |
| 44 | + } |
| 45 | + ``` |
| 46 | + |
| 47 | +2. **Create lint parser abstraction** (`src/lib/lint-parsers.ts`): |
| 48 | + ```typescript |
| 49 | + interface LintParser { |
| 50 | + parseOutput(output: string, filePath?: string): ParsedLintResult; |
| 51 | + getAutoFixCommand(baseCommand: string): string | undefined; |
| 52 | + } |
| 53 | + |
| 54 | + class BiomeParser implements LintParser { |
| 55 | + // Parse "X diagnostics" format |
| 56 | + // Parse compact reporter format for file-specific errors |
| 57 | + // Return structured errors with line numbers |
| 58 | + } |
| 59 | + |
| 60 | + class ESLintParser implements LintParser { |
| 61 | + // Parse ESLint stylish or compact format |
| 62 | + // Extract error/warning counts |
| 63 | + // Handle various ESLint output formats |
| 64 | + } |
| 65 | + |
| 66 | + class GenericParser implements LintParser { |
| 67 | + // Simple line-based error matching |
| 68 | + // Fallback for unknown tools |
| 69 | + } |
| 70 | + ``` |
| 71 | + |
| 72 | +3. **Refactor `src/lib/validation.ts`**: |
| 73 | + - **Line 93**: Rename function `runBiomeCheck` → `runLintCheck` |
| 74 | + - **Line 95-101**: Replace hardcoded auto-formatter with: |
| 75 | + ```typescript |
| 76 | + if (lintConfig?.autoFixCommand) { |
| 77 | + try { |
| 78 | + execSync(lintConfig.autoFixCommand, { cwd: projectRoot }); |
| 79 | + } catch { |
| 80 | + // Auto-fix might fail, continue to check |
| 81 | + } |
| 82 | + } |
| 83 | + ``` |
| 84 | + - **Line 107-109**: Remove automatic `--error-on-warnings` addition |
| 85 | + - **Line 119-127**: Replace Biome-specific parsing with parser abstraction: |
| 86 | + ```typescript |
| 87 | + const parser = getLintParser(lintConfig?.tool || 'biome'); |
| 88 | + const result = parser.parseOutput(output); |
| 89 | + ``` |
| 90 | + - Update all variable names: `biomeConfig` → `lintConfig`, `biomeCheck` → `lintCheck` |
| 91 | + |
| 92 | +4. **Refactor `src/hooks/edit-validation.ts`**: |
| 93 | + - **Line 178**: Rename function `runBiomeCheck` → `runLintCheck` |
| 94 | + - **Line 192**: Remove hardcoded `--reporter=compact`, use command as-is |
| 95 | + - **Line 208-213**: Replace Biome-specific parsing with: |
| 96 | + ```typescript |
| 97 | + const parser = getLintParser(config.lint?.tool || 'biome'); |
| 98 | + const errors = parser.parseOutput(output, filePath); |
| 99 | + ``` |
| 100 | + - Update function signature and all references |
| 101 | + |
| 102 | +5. **Update ValidationResult interface** (multiple files): |
| 103 | + - Change `biome?: { ... }` to `lint?: { ... }` |
| 104 | + - Keep the same structure (passed, errors, issueCount) |
| 105 | + - Update all references in: |
| 106 | + - `src/lib/validation.ts` |
| 107 | + - `src/commands/prepare-completion.ts` |
| 108 | + - `src/commands/complete-task.ts` |
| 109 | + - Test files |
| 110 | + |
| 111 | +6. **Update user-facing messages in `src/commands/prepare-completion.ts`**: |
| 112 | + - **Line 283**: Change "Biome issues" to "Linting issues" |
| 113 | + - **Line 292**: Generate tool-specific fix advice: |
| 114 | + ```typescript |
| 115 | + const lintTool = config.lint?.tool || 'biome'; |
| 116 | + const fixAdvice = { |
| 117 | + biome: 'Fix with `bunx biome check --write`', |
| 118 | + eslint: 'Fix with `npx eslint --fix`', |
| 119 | + custom: config.lint?.autoFixCommand |
| 120 | + ? `Fix with \`${config.lint.autoFixCommand}\`` |
| 121 | + : 'Fix linting issues manually' |
| 122 | + }; |
| 123 | + messages.push(`**Action:** ${fixAdvice[lintTool]}.\n`); |
| 124 | + ``` |
| 125 | + |
| 126 | +7. **Backward compatibility handling**: |
| 127 | + - In config loading, detect old format (just `command` string) |
| 128 | + - If old format detected, convert to new format assuming Biome: |
| 129 | + ```typescript |
| 130 | + if (typeof config.lint === 'object' && !config.lint.tool) { |
| 131 | + config.lint.tool = 'biome'; // Assume Biome for existing configs |
| 132 | + } |
| 133 | + ``` |
| 134 | + |
| 135 | +8. **Update default configurations**: |
| 136 | + - `src/lib/config.ts`: Update default lint config structure |
| 137 | + - Template files: Update to show new config format |
| 138 | + - Documentation: Add examples for ESLint configuration |
| 139 | + |
| 140 | +9. **Add comprehensive tests**: |
| 141 | + - Test Biome output parsing with various error formats |
| 142 | + - Test ESLint output parsing (stylish, compact formats) |
| 143 | + - Test generic parser fallback |
| 144 | + - Test backward compatibility with old configs |
| 145 | + - Test both validation.ts and edit-validation.ts with different tools |
| 146 | + |
| 147 | +10. **Update documentation**: |
| 148 | + - README: Show examples for both Biome and ESLint configuration |
| 149 | + - Comments in code: Update to be tool-agnostic |
| 150 | + - Config template: Include commented examples for different tools |
| 151 | + |
| 152 | +### Implementation Order: |
| 153 | +1. Create lint-parsers.ts with all three parser implementations |
| 154 | +2. Update config types and interfaces |
| 155 | +3. Refactor validation.ts to use parsers |
| 156 | +4. Refactor edit-validation.ts to use parsers |
| 157 | +5. Update prepare-completion.ts messages |
| 158 | +6. Add backward compatibility logic |
| 159 | +7. Update all tests |
| 160 | +8. Update documentation and templates |
| 161 | + |
| 162 | +This approach maintains full detail while supporting Biome and ESLint as first-class citizens, with the flexibility to support other tools through the custom parser option. |
0 commit comments