From 15e117d10c9dea3bf0f2ce3137600e9e45fa9c86 Mon Sep 17 00:00:00 2001 From: Claude Code Date: Sat, 5 Jul 2025 22:41:14 -0400 Subject: [PATCH] Clean up unused imports and variables to improve code quality MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Remove unused imports: LocationSubmission from types, Location/ProfanityWord from server - Remove unused variables: wordText, detectedWords in profanity rejection - Remove unused parameters: req in skip function, wordId/updates in fallback filter - Fix regex escaping and destructuring patterns - Remove unused response variables in tests - Reduce ESLint issues from 45 to 22 (eliminated all 21 errors, keeping only warnings) 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- src/routes/locations.ts | 6 +----- src/server.ts | 6 ++---- src/services/ProfanityFilterService.ts | 8 ++++---- tests/integration/routes/admin.test.ts | 4 ++-- tests/integration/routes/public.test.ts | 2 +- tests/setup.ts | 2 -- tests/unit/services/DatabaseService.test.ts | 2 +- 7 files changed, 11 insertions(+), 19 deletions(-) diff --git a/src/routes/locations.ts b/src/routes/locations.ts index ddbe511..798e611 100644 --- a/src/routes/locations.ts +++ b/src/routes/locations.ts @@ -2,7 +2,6 @@ import express, { Request, Response, Router } from 'express'; import rateLimit from 'express-rate-limit'; import Location from '../models/Location'; import ProfanityFilterService from '../services/ProfanityFilterService'; -import { LocationSubmission } from '../types'; // Define interfaces for request bodies interface LocationPostRequest extends Request { @@ -30,7 +29,7 @@ export default (locationModel: Location, profanityFilter: ProfanityFilterService standardHeaders: true, // Return rate limit info in the `RateLimit-*` headers legacyHeaders: false, // Disable the `X-RateLimit-*` headers // Skip rate limiting in test environment - skip: (req) => process.env.NODE_ENV === 'test' + skip: () => process.env.NODE_ENV === 'test' }); /** @@ -215,9 +214,6 @@ export default (locationModel: Location, profanityFilter: ProfanityFilterService console.warn(`Submission rejected due to inappropriate language (${analysis.count} word${analysis.count > 1 ? 's' : ''}, severity: ${analysis.severity}) - Original: "${req.body.description}"`); // Reject any submission with profanity - const wordText = analysis.count === 1 ? 'word' : 'words'; - const detectedWords = analysis.matches.map((m: any) => m.word).join(', '); - res.status(400).json({ error: 'Submission rejected', message: 'Your description contains inappropriate language and cannot be posted. Please revise your description to focus on road conditions and keep it professional.\n\nExample: "Multiple vehicles stuck, black ice present" or "Road very slippery, saw 3 accidents"', diff --git a/src/server.ts b/src/server.ts index 73105a9..88ef48d 100644 --- a/src/server.ts +++ b/src/server.ts @@ -19,8 +19,6 @@ import configRoutes from './routes/config'; import locationRoutes from './routes/locations'; import adminRoutes from './routes/admin'; -// Import types -import { Location, ProfanityWord } from './types'; const app: Application = express(); const PORT: number = parseInt(process.env.PORT || '3000', 10); @@ -84,11 +82,11 @@ function createFallbackFilter(): FallbackFilter { success: false, error: 'Profanity filter not available - please check server configuration' }), - removeCustomWord: async (wordId: number) => ({ + removeCustomWord: async () => ({ success: false, error: 'Profanity filter not available - please check server configuration' }), - updateCustomWord: async (wordId: number, updates: any) => ({ + updateCustomWord: async () => ({ success: false, error: 'Profanity filter not available - please check server configuration' }), diff --git a/src/services/ProfanityFilterService.ts b/src/services/ProfanityFilterService.ts index 5f8bb7f..890fd98 100644 --- a/src/services/ProfanityFilterService.ts +++ b/src/services/ProfanityFilterService.ts @@ -155,8 +155,8 @@ class ProfanityFilterService { .split('') .map(char => { const leetChars = Object.entries(this.leetMap) - .filter(([_, v]) => v === char.toLowerCase()) - .map(([k, _]) => k); + .filter(([, v]) => v === char.toLowerCase()) + .map(([k]) => k); if (leetChars.length > 0) { const allChars = [char, ...leetChars].map(c => @@ -234,7 +234,7 @@ class ProfanityFilterService { let normalized = text.toLowerCase(); // Replace multiple spaces/special chars with single space - normalized = normalized.replace(/[\s\-\_\*\.]+/g, ' '); + normalized = normalized.replace(/[\s\-_*.]+/g, ' '); // Apply leet speak conversions normalized = normalized.split('').map(char => @@ -317,7 +317,7 @@ class ProfanityFilterService { /** * Filter profanity from text */ - filterProfanity(text: string, replacementChar: string = '*'): string { + filterProfanity(text: string): string { const analysis = this.analyzeProfanity(text); return analysis.filtered; } diff --git a/tests/integration/routes/admin.test.ts b/tests/integration/routes/admin.test.ts index 8a63f29..6b6b955 100644 --- a/tests/integration/routes/admin.test.ts +++ b/tests/integration/routes/admin.test.ts @@ -510,7 +510,7 @@ describe('Admin API Routes', () => { }); it('should handle malformed JSON in request body', async () => { - const response = await request(app) + await request(app) .post('/api/admin/profanity-words') .set('Authorization', `Bearer ${authToken}`) .set('Content-Type', 'application/json') @@ -521,7 +521,7 @@ describe('Admin API Routes', () => { }); it('should handle missing content-type header', async () => { - const response = await request(app) + await request(app) .post('/api/admin/profanity-words') .set('Authorization', `Bearer ${authToken}`) .send('word=test&severity=low&category=test') diff --git a/tests/integration/routes/public.test.ts b/tests/integration/routes/public.test.ts index 1083bf1..07b856b 100644 --- a/tests/integration/routes/public.test.ts +++ b/tests/integration/routes/public.test.ts @@ -302,7 +302,7 @@ describe('Public API Routes', () => { }); it('should handle malformed JSON', async () => { - const response = await request(app) + await request(app) .post('/api/locations') .set('Content-Type', 'application/json') .send('{"address": "Test Location"') // Missing closing brace diff --git a/tests/setup.ts b/tests/setup.ts index d07f999..714c1bc 100644 --- a/tests/setup.ts +++ b/tests/setup.ts @@ -1,6 +1,4 @@ import { Database } from 'sqlite3'; -import fs from 'fs'; -import path from 'path'; // Setup test environment process.env.NODE_ENV = 'test'; diff --git a/tests/unit/services/DatabaseService.test.ts b/tests/unit/services/DatabaseService.test.ts index 1157977..9a191c4 100644 --- a/tests/unit/services/DatabaseService.test.ts +++ b/tests/unit/services/DatabaseService.test.ts @@ -16,7 +16,7 @@ describe('DatabaseService', () => { jest.restoreAllMocks(); try { databaseService.close(); - } catch (e) { + } catch { // Ignore close errors in tests } });