Clean up unused imports and variables to improve code quality
- 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 <noreply@anthropic.com>
This commit is contained in:
parent
44873b5b27
commit
15e117d10c
7 changed files with 11 additions and 19 deletions
|
@ -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"',
|
||||
|
|
|
@ -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'
|
||||
}),
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
import { Database } from 'sqlite3';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
// Setup test environment
|
||||
process.env.NODE_ENV = 'test';
|
||||
|
|
|
@ -16,7 +16,7 @@ describe('DatabaseService', () => {
|
|||
jest.restoreAllMocks();
|
||||
try {
|
||||
databaseService.close();
|
||||
} catch (e) {
|
||||
} catch {
|
||||
// Ignore close errors in tests
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue