From 266e06896f7728b0280749316625e57d11e322d9 Mon Sep 17 00:00:00 2001 From: Continue Agent Date: Tue, 21 Oct 2025 23:28:30 +0000 Subject: [PATCH] Clean up codebase: remove console.logs, unused imports, fix formatting - Removed all console.log statements from api/users.ts and src/utils/messyCode.ts - Removed unused imports (fs from api/users.ts, path/readFile/crypto from messyCode.ts) - Removed unused variables and code from messyCode.ts - Fixed formatting issues with ESLint and Prettier - Fixed inconsistent indentation, spacing, and quotes - Removed unused imports from test files - Ensured consistent code style throughout the codebase Note: Console statements in logger.ts are intentional (logger implementation) Generated with Continue (https://continue.dev) Co-authored-by: Username --- __tests__/math.test.ts | 10 ++--- __tests__/todoApp.test.ts | 36 +++++++-------- __tests__/users.test.ts | 2 +- api/users.ts | 14 ++---- index.ts | 8 ++-- src/bonus/todoApp.ts | 16 ++++--- src/helpers/logger.ts | 22 ++++----- src/utils/math.ts | 6 +-- src/utils/messyCode.ts | 95 ++++++--------------------------------- 9 files changed, 70 insertions(+), 139 deletions(-) diff --git a/__tests__/math.test.ts b/__tests__/math.test.ts index 0a29e79..b2b6610 100644 --- a/__tests__/math.test.ts +++ b/__tests__/math.test.ts @@ -4,7 +4,7 @@ * Many functions are not tested, and edge cases are missing */ -import { add, subtract, multiply, divide, factorial, isPrime, average, findMax } from '../src/utils/math'; +import { add, subtract, divide, isPrime } from '../src/utils/math'; describe('Math Utilities', () => { // Basic tests for add function @@ -21,7 +21,7 @@ describe('Math Utilities', () => { it('should subtract two numbers', () => { expect(subtract(5, 3)).toBe(2); }); - + // Missing: negative results, zero cases }); @@ -35,7 +35,7 @@ describe('Math Utilities', () => { it('should divide two numbers', () => { expect(divide(10, 2)).toBe(5); }); - + // BUG: Missing test for division by zero! // This would catch the bug in the divide function }); @@ -51,7 +51,7 @@ describe('Math Utilities', () => { it('should return true for 7', () => { expect(isPrime(7)).toBe(true); }); - + // Missing: test for 1, 2, negative numbers, non-prime numbers }); @@ -60,4 +60,4 @@ describe('Math Utilities', () => { // No tests for findMax function! // This function also has issues with empty arrays -}); \ No newline at end of file +}); diff --git a/__tests__/todoApp.test.ts b/__tests__/todoApp.test.ts index 05a9322..87d5929 100644 --- a/__tests__/todoApp.test.ts +++ b/__tests__/todoApp.test.ts @@ -4,7 +4,7 @@ * Users can add these via workflows */ -import { TodoApp, Todo } from '../src/bonus/todoApp'; +import { TodoApp } from '../src/bonus/todoApp'; describe('TodoApp', () => { let app: TodoApp; @@ -16,7 +16,7 @@ describe('TodoApp', () => { describe('addTodo', () => { it('should add a new todo with default priority', () => { const todo = app.addTodo('Test todo'); - + expect(todo.title).toBe('Test todo'); expect(todo.completed).toBe(false); expect(todo.priority).toBe('medium'); @@ -25,7 +25,7 @@ describe('TodoApp', () => { it('should add a todo with custom priority', () => { const todo = app.addTodo('Urgent task', 'Fix critical bug', 'high'); - + expect(todo.priority).toBe('high'); expect(todo.description).toBe('Fix critical bug'); }); @@ -36,7 +36,7 @@ describe('TodoApp', () => { app.addTodo('Todo 1'); app.addTodo('Todo 2'); app.addTodo('Todo 3'); - + const todos = app.getAllTodos(); expect(todos).toHaveLength(3); }); @@ -50,7 +50,7 @@ describe('TodoApp', () => { it('should return todo by ID', () => { const todo1 = app.addTodo('First'); const todo2 = app.addTodo('Second'); - + expect(app.getTodoById(1)).toEqual(todo1); expect(app.getTodoById(2)).toEqual(todo2); }); @@ -63,9 +63,9 @@ describe('TodoApp', () => { describe('completeTodo', () => { it('should mark todo as completed', () => { const todo = app.addTodo('Complete me'); - + const result = app.completeTodo(todo.id); - + expect(result).toBe(true); expect(app.getTodoById(todo.id)?.completed).toBe(true); }); @@ -78,9 +78,9 @@ describe('TodoApp', () => { describe('deleteTodo', () => { it('should delete a todo', () => { const todo = app.addTodo('Delete me'); - + const result = app.deleteTodo(todo.id); - + expect(result).toBe(true); expect(app.getTodoById(todo.id)).toBeUndefined(); expect(app.getAllTodos()).toHaveLength(0); @@ -96,11 +96,11 @@ describe('TodoApp', () => { const todo1 = app.addTodo('Incomplete 1'); const todo2 = app.addTodo('Complete me'); const todo3 = app.addTodo('Incomplete 2'); - + app.completeTodo(todo2.id); - + const incomplete = app.getIncompleteTodos(); - + expect(incomplete).toHaveLength(2); expect(incomplete.map(t => t.id)).toEqual([todo1.id, todo3.id]); }); @@ -109,21 +109,21 @@ describe('TodoApp', () => { describe('getCompletedTodos', () => { it('should return only completed todos', () => { const todo1 = app.addTodo('Todo 1'); - const todo2 = app.addTodo('Todo 2'); + app.addTodo('Todo 2'); const todo3 = app.addTodo('Todo 3'); - + app.completeTodo(todo1.id); app.completeTodo(todo3.id); - + const completed = app.getCompletedTodos(); - + expect(completed).toHaveLength(2); expect(completed.map(t => t.id)).toEqual([todo1.id, todo3.id]); }); }); // TODO: Tests for features to be implemented via workflows - + describe.skip('markAllAsCompleted', () => { it('should mark all todos as completed', () => { // This test will be added when the feature is implemented @@ -147,4 +147,4 @@ describe('TodoApp', () => { // This test will be added when the feature is implemented }); }); -}); \ No newline at end of file +}); diff --git a/__tests__/users.test.ts b/__tests__/users.test.ts index 38bd93e..41137cc 100644 --- a/__tests__/users.test.ts +++ b/__tests__/users.test.ts @@ -54,4 +54,4 @@ describe('Users API', () => { expect(formatUserName(user)).toBe('JOHN DOE'); }); }); -}); \ No newline at end of file +}); diff --git a/api/users.ts b/api/users.ts index 45a29e0..fc24565 100644 --- a/api/users.ts +++ b/api/users.ts @@ -48,19 +48,13 @@ export function isAdmin(userId: number): boolean { return user.role === 'admin'; } -// Unused import that should be cleaned up (for Workflow #2) -import * as fs from 'fs'; - -// Console.log that should be removed (for Workflow #2) -console.log('Users API loaded'); - /** * Format user display name * Missing proper formatting and has inconsistent spacing */ export function formatUserName(user: User): string { - // Inconsistent indentation (for ESLint to catch) - const displayName=user.name.toUpperCase(); // Missing spaces around = - return displayName + // Inconsistent indentation (for ESLint to catch) + const displayName = user.name.toUpperCase(); // Missing spaces around = + return displayName; // Missing semicolon above (for Prettier to fix) -} \ No newline at end of file +} diff --git a/index.ts b/index.ts index c4880cd..107d668 100644 --- a/index.ts +++ b/index.ts @@ -3,8 +3,8 @@ * This file demonstrates how the various modules work together */ -import { getUserById, getUserEmail, isAdmin } from './api/users'; -import { add, subtract, multiply, divide } from './src/utils/math'; +import { getUserById, getUserEmail } from './api/users'; +import { add, multiply, divide } from './src/utils/math'; import { createLogger } from './src/helpers/logger'; import { TodoApp } from './src/bonus/todoApp'; @@ -16,7 +16,7 @@ logger.info('Testing Users API...'); try { const user = getUserById(1); logger.info(`Found user: ${user.name}`); - + // This will cause an error with non-existent user const email = getUserEmail(999); logger.info(`User email: ${email}`); @@ -48,4 +48,4 @@ const incomplete = todoApp.getIncompleteTodos(); logger.info(`${incomplete.length} todos remaining`); // Export for testing -export { todoApp, logger }; \ No newline at end of file +export { todoApp, logger }; diff --git a/src/bonus/todoApp.ts b/src/bonus/todoApp.ts index 6e4e6a6..4a31bcd 100644 --- a/src/bonus/todoApp.ts +++ b/src/bonus/todoApp.ts @@ -20,7 +20,11 @@ export class TodoApp { /** * Add a new todo item */ - addTodo(title: string, description?: string, priority: 'low' | 'medium' | 'high' = 'medium'): Todo { + addTodo( + title: string, + description?: string, + priority: 'low' | 'medium' | 'high' = 'medium' + ): Todo { const todo: Todo = { id: this.nextId++, title, @@ -29,7 +33,7 @@ export class TodoApp { createdAt: new Date(), priority }; - + this.todos.push(todo); return todo; } @@ -88,13 +92,13 @@ export class TodoApp { // FEATURE REQUEST: Add a method to mark all todos as completed // This is intentionally missing for users to implement via workflows - + // FEATURE REQUEST: Add a method to get todos by priority // This is intentionally missing for users to implement via workflows - + // FEATURE REQUEST: Add a method to update todo details // This is intentionally missing for users to implement via workflows - + // FEATURE REQUEST: Add a method to clear all completed todos // This is intentionally missing for users to implement via workflows } @@ -106,4 +110,4 @@ app.addTodo('Fix bug in users.ts', 'TypeError when user not found', 'high'); app.addTodo('Add unit tests', 'Cover all math functions', 'medium'); app.addTodo('Update dependencies', 'Security vulnerabilities', 'high'); app.addTodo('Add documentation', 'JSDoc comments needed', 'low'); -*/ \ No newline at end of file +*/ diff --git a/src/helpers/logger.ts b/src/helpers/logger.ts index 66e44f1..237cf70 100644 --- a/src/helpers/logger.ts +++ b/src/helpers/logger.ts @@ -81,16 +81,16 @@ export function createLogger(prefix?: string, level?: LogLevel): Logger { // Missing JSDoc comment export function parseLogLevel(level: string): LogLevel { switch (level.toUpperCase()) { - case 'DEBUG': - return LogLevel.DEBUG; - case 'INFO': - return LogLevel.INFO; - case 'WARN': - return LogLevel.WARN; - case 'ERROR': - return LogLevel.ERROR; - default: - return LogLevel.INFO; + case 'DEBUG': + return LogLevel.DEBUG; + case 'INFO': + return LogLevel.INFO; + case 'WARN': + return LogLevel.WARN; + case 'ERROR': + return LogLevel.ERROR; + default: + return LogLevel.INFO; } } @@ -99,4 +99,4 @@ export function formatError(error: Error): string { return `${error.name}: ${error.message}\n${error.stack}`; } -export { Logger, LogLevel }; \ No newline at end of file +export { Logger, LogLevel }; diff --git a/src/utils/math.ts b/src/utils/math.ts index 2e956b2..08983bc 100644 --- a/src/utils/math.ts +++ b/src/utils/math.ts @@ -67,14 +67,14 @@ export function factorial(n: number): number { export function isPrime(n: number): boolean { // Edge case: numbers less than 2 are not prime if (n < 2) return false; - + // Check for divisibility up to square root of n for (let i = 2; i <= Math.sqrt(n); i++) { if (n % i === 0) { return false; } } - + return true; } @@ -97,4 +97,4 @@ export function average(numbers: number[]): number { export function findMax(numbers: number[]): number { // BUG: What happens with empty array? return Math.max(...numbers); -} \ No newline at end of file +} diff --git a/src/utils/messyCode.ts b/src/utils/messyCode.ts index 40f6a16..5aaaf1a 100644 --- a/src/utils/messyCode.ts +++ b/src/utils/messyCode.ts @@ -3,95 +3,28 @@ * Used for demonstrating Workflow #2 - Code Cleanup */ -// Unused imports that should be removed -import * as path from 'path'; -import { readFile } from 'fs'; -import * as crypto from 'crypto'; - -// Inconsistent quotes -const message1 = "This uses double quotes"; -const message2 = 'This uses single quotes'; - -// Console.logs that should be removed -console.log("Debug: Starting application"); -console.log('Another console statement'); - // Inconsistent spacing and formatting -function calculateSum (a:number,b:number):number{ -return a+b; +function calculateSum(a: number, b: number): number { + return a + b; } -// Missing semicolons -const value1 = 42 -const value2 = "test" -let value3 = true - // Inconsistent indentation -function processData(data: any) { -if (data) { - // Wrong indentation - const result = data.toString() - // More wrong indentation - return result.toUpperCase() - } else { - return null -} +function processData(data: string | null): string | null { + if (data) { + // Wrong indentation + const result = data.toString(); + // More wrong indentation + return result.toUpperCase(); + } else { + return null; + } } -// var instead of let/const -var oldStyleVariable = "should use const"; -var anotherVar = 123; - -// Unused variables -const unusedVariable = "I'm never used"; -const anotherUnused = { key: "value" }; - -// Inconsistent object spacing -const obj1 = {key1:"value1",key2:"value2"}; -const obj2 = { key1: "value1" , key2 : "value2" }; - -// Inconsistent array spacing -const arr1 = [1,2,3,4,5]; -const arr2 = [ 1 , 2 , 3 , 4 , 5 ]; - // Functions with any type -function processAny(input: any): any { - return input; +function processAny(input: string): string { + return input; } -// Template literals not used where they should be -const name = "User"; -const greeting = "Hello, " + name + "!"; - -// Arrow function inconsistency -const arrow1 = (x) => x * 2; -const arrow2 = x=> { return x * 2 }; - -// Trailing commas inconsistency -const config = { - option1: true, - option2: false, - option3: "maybe", // Has trailing comma -} - -const config2 = { - option1: true, - option2: false, - option3: "maybe" // No trailing comma -} - -// Mixed async patterns (could be improved) -function fetchDataCallback(callback: Function) { - setTimeout(() => { - callback("data"); - }, 1000); -} - -// More console.logs to clean up -console.warn("This is a warning"); -console.error("This is an error"); -console.debug("Debug info"); - // Inconsistent exports export default calculateSum; -export { processData, processAny }; \ No newline at end of file +export { processData, processAny };