Skip to content

Commit 2a38d06

Browse files
sjsyrekclaude
andcommitted
fix(lint): resolve all ESLint errors across codebase
Remove unused variable, fix async/await patterns, use nullish coalescing, and eliminate unsafe non-null assertions. Changes: - Remove unused `processedTextsCount` variable in translation service - Replace `||` with `??` for safer nullish coalescing in tests - Convert jest callback tests to async/await pattern - Fix optional chain non-null assertion by using proper type guards - Remove unnecessary async keyword from non-awaiting mock function All tests passing (1461 tests). Zero lint errors remaining. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent b9223ed commit 2a38d06

5 files changed

Lines changed: 65 additions & 52 deletions

File tree

src/services/translation.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,6 @@ export class TranslationService {
210210
// Use a Map to correctly track which text maps to which result
211211
const textToResultMap = new Map<string, TranslationResult>();
212212
let lastError: Error | null = null;
213-
let processedTextsCount = 0; // Track position in textsToTranslate array
214213

215214
for (const batch of batches) {
216215
try {
@@ -224,13 +223,10 @@ export class TranslationService {
224223
textToResultMap.set(text, result);
225224
}
226225
}
227-
228-
processedTextsCount += batch.length;
229226
} catch (error) {
230227
lastError = error as Error;
231228
Logger.error(`Batch translation failed: ${error instanceof Error ? error.message : String(error)}`);
232229
// Mark all texts in this batch as processed (but failed)
233-
processedTextsCount += batch.length;
234230
// Continue with other batches rather than failing completely
235231
}
236232
}

tests/integration/batch-translation.integration.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ jest.mock('p-limit', () => ({
1919
// Mock fast-glob with implementation inline
2020
jest.mock('fast-glob', () => ({
2121
__esModule: true,
22-
default: async (pattern: string | string[], options: any) => {
22+
default: (pattern: string | string[], options: any) => {
2323
// Simple mock implementation that scans directories
24-
const globPattern = (Array.isArray(pattern) ? pattern[0] : pattern) || '';
24+
const globPattern = (Array.isArray(pattern) ? pattern[0] : pattern) ?? '';
2525

2626
// Extract base directory from pattern by removing glob parts
2727
let baseDir = globPattern;
2828
if (baseDir.includes('**')) {
29-
baseDir = baseDir.split('**')[0] || '';
29+
baseDir = baseDir.split('**')[0] ?? '';
3030
}
3131
baseDir = baseDir.replace(/[/*]+$/, '');
3232

@@ -36,7 +36,7 @@ jest.mock('fast-glob', () => ({
3636

3737
// Recursively scan directory
3838
const scanDir = (dir: string, currentDepth: number = 0): string[] => {
39-
if (!fs.existsSync(dir)) return [];
39+
if (!fs.existsSync(dir)) {return [];}
4040

4141
const entries = fs.readdirSync(dir, { withFileTypes: true });
4242
const files: string[] = [];

tests/integration/cli-translate-workflow.integration.test.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ describe('Translation Workflow Integration', () => {
3838
proxy: {},
3939
}),
4040
getValue: (key: string) => {
41-
if (key === 'cache.enabled') return true;
41+
if (key === 'cache.enabled') {return true;}
4242
return undefined;
4343
},
4444
} as unknown as ConfigService;
@@ -275,7 +275,7 @@ describe('Translation Workflow Integration', () => {
275275
mockConfig = {
276276
get: () => ({ defaults: {} }),
277277
getValue: (key: string) => {
278-
if (key === 'cache.enabled') return false;
278+
if (key === 'cache.enabled') {return false;}
279279
return undefined;
280280
},
281281
} as ConfigService;
@@ -653,11 +653,18 @@ describe('Translation Workflow Integration', () => {
653653
expect(results[0]?.outputPath).toBe(path.join(outputDir, 'input.es.txt'));
654654
expect(results[1]?.outputPath).toBe(path.join(outputDir, 'input.fr.txt'));
655655

656-
expect(fs.existsSync(results[0]?.outputPath!)).toBe(true);
657-
expect(fs.existsSync(results[1]?.outputPath!)).toBe(true);
656+
const outputPath0 = results[0]?.outputPath;
657+
const outputPath1 = results[1]?.outputPath;
658+
expect(outputPath0).toBeDefined();
659+
expect(outputPath1).toBeDefined();
658660

659-
expect(fs.readFileSync(results[0]?.outputPath!, 'utf-8')).toBe('Hola');
660-
expect(fs.readFileSync(results[1]?.outputPath!, 'utf-8')).toBe('Bonjour');
661+
if (outputPath0 && outputPath1) {
662+
expect(fs.existsSync(outputPath0)).toBe(true);
663+
expect(fs.existsSync(outputPath1)).toBe(true);
664+
665+
expect(fs.readFileSync(outputPath0, 'utf-8')).toBe('Hola');
666+
expect(fs.readFileSync(outputPath1, 'utf-8')).toBe('Bonjour');
667+
}
661668
});
662669

663670
it('should throw error for non-existent input file', async () => {

tests/integration/cli-watch.integration.test.ts

Lines changed: 46 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -170,44 +170,52 @@ describe('Watch Service Integration', () => {
170170
});
171171

172172
describe('handleFileChange() - Callbacks', () => {
173-
it('should call onChange callback when file changes', (done) => {
173+
it('should call onChange callback when file changes', async () => {
174174
const testFile = path.join(tmpDir, 'test.txt');
175175
fs.writeFileSync(testFile, 'Hello');
176176

177-
const onChangeMock = jest.fn((filePath: string) => {
178-
expect(filePath).toBe(testFile);
179-
done();
180-
});
177+
const callbackPromise = new Promise<void>((resolve) => {
178+
const onChangeMock = jest.fn((filePath: string) => {
179+
expect(filePath).toBe(testFile);
180+
resolve();
181+
});
181182

182-
watchService.watch(testFile, {
183-
targetLangs: ['es'],
184-
outputDir: tmpDir,
185-
onChange: onChangeMock,
183+
watchService.watch(testFile, {
184+
targetLangs: ['es'],
185+
outputDir: tmpDir,
186+
onChange: onChangeMock,
187+
});
188+
189+
watchService.handleFileChange(testFile);
186190
});
187191

188-
watchService.handleFileChange(testFile);
192+
await callbackPromise;
189193
});
190194

191-
it('should call onError callback when translation fails', (done) => {
195+
it('should call onError callback when translation fails', async () => {
192196
const testFile = path.join(tmpDir, 'test.txt');
193197
fs.writeFileSync(testFile, 'Hello');
194198

195199
// Mock translation service to throw error
196200
jest.spyOn(fileTranslationService, 'translateFile').mockRejectedValue(new Error('API error'));
197201

198-
const onErrorMock = jest.fn((filePath: string, error: Error) => {
199-
expect(filePath).toBe(testFile);
200-
expect(error.message).toContain('API error');
201-
done();
202-
});
202+
const callbackPromise = new Promise<void>((resolve) => {
203+
const onErrorMock = jest.fn((filePath: string, error: Error) => {
204+
expect(filePath).toBe(testFile);
205+
expect(error.message).toContain('API error');
206+
resolve();
207+
});
203208

204-
watchService.watch(testFile, {
205-
targetLangs: ['es'],
206-
outputDir: tmpDir,
207-
onError: onErrorMock,
209+
watchService.watch(testFile, {
210+
targetLangs: ['es'],
211+
outputDir: tmpDir,
212+
onError: onErrorMock,
213+
});
214+
215+
watchService.handleFileChange(testFile);
208216
});
209217

210-
watchService.handleFileChange(testFile);
218+
await callbackPromise;
211219
});
212220
});
213221

@@ -234,23 +242,27 @@ describe('Watch Service Integration', () => {
234242
expect(stats.isWatching).toBe(true);
235243
});
236244

237-
it('should increment error count on translation failure', (done) => {
245+
it('should increment error count on translation failure', async () => {
238246
const testFile = path.join(tmpDir, 'test.txt');
239247
fs.writeFileSync(testFile, 'Hello');
240248

241249
jest.spyOn(fileTranslationService, 'translateFile').mockRejectedValue(new Error('Fail'));
242250

243-
watchService.watch(testFile, {
244-
targetLangs: ['es'],
245-
outputDir: tmpDir,
246-
onError: () => {
247-
const stats = watchService.getStats();
248-
expect(stats.errorsCount).toBeGreaterThan(0);
249-
done();
250-
},
251+
const callbackPromise = new Promise<void>((resolve) => {
252+
watchService.watch(testFile, {
253+
targetLangs: ['es'],
254+
outputDir: tmpDir,
255+
onError: () => {
256+
const stats = watchService.getStats();
257+
expect(stats.errorsCount).toBeGreaterThan(0);
258+
resolve();
259+
},
260+
});
261+
262+
watchService.handleFileChange(testFile);
251263
});
252264

253-
watchService.handleFileChange(testFile);
265+
await callbackPromise;
254266
});
255267
});
256268

@@ -355,7 +367,7 @@ describe('Watch Service Integration', () => {
355367
});
356368

357369
describe('Debouncing', () => {
358-
it('should debounce rapid file changes', (done) => {
370+
it('should debounce rapid file changes', async () => {
359371
const testFile = path.join(tmpDir, 'test.txt');
360372
fs.writeFileSync(testFile, 'Hello');
361373

@@ -376,10 +388,8 @@ describe('Watch Service Integration', () => {
376388
watchService.handleFileChange(testFile);
377389

378390
// onChange should be called 3 times (once per trigger)
379-
setTimeout(() => {
380-
expect(changeCount).toBe(3);
381-
done();
382-
}, 100);
391+
await new Promise((resolve) => setTimeout(resolve, 100));
392+
expect(changeCount).toBe(3);
383393
});
384394
});
385395
});

tests/unit/translation-service.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ describe('TranslationService', () => {
646646
});
647647

648648
// Should preserve all three {name} instances
649-
const nameCount = (result.text.match(/\{name\}/g) || []).length;
649+
const nameCount = (result.text.match(/\{name\}/g) ?? []).length;
650650
expect(nameCount).toBe(3);
651651
});
652652

@@ -664,7 +664,7 @@ describe('TranslationService', () => {
664664

665665
// Check that the text sent to API has three DIFFERENT placeholders
666666
// (even though the original had three identical variables)
667-
const placeholders = receivedText.match(/__VAR_\w+__/g) || [];
667+
const placeholders = receivedText.match(/__VAR_\w+__/g) ?? [];
668668
expect(placeholders.length).toBe(3);
669669

670670
// All placeholders should be unique (no collisions)

0 commit comments

Comments
 (0)