Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions __tests__/math.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -21,7 +21,7 @@ describe('Math Utilities', () => {
it('should subtract two numbers', () => {
expect(subtract(5, 3)).toBe(2);
});

// Missing: negative results, zero cases
});

Expand Down
8 changes: 4 additions & 4 deletions __tests__/todoApp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -94,10 +94,10 @@ describe('TodoApp', () => {
describe('getIncompleteTodos', () => {
it('should return only incomplete todos', () => {
const todo1 = app.addTodo('Incomplete 1');
const todo2 = app.addTodo('Complete me');
const _todo2 = app.addTodo('Complete me');
const todo3 = app.addTodo('Incomplete 2');

app.completeTodo(todo2.id);
app.completeTodo(_todo2.id);

const incomplete = app.getIncompleteTodos();

Expand All @@ -109,7 +109,7 @@ 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);
Expand Down
2 changes: 1 addition & 1 deletion __tests__/users.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('Users API', () => {
it('should return a user when given a valid ID', () => {
const user = getUserById(1);
expect(user).toBeDefined();
expect(user.name).toBe('Alice Johnson');
expect(user?.name).toBe('Alice Johnson');
});

// This test will FAIL due to the bug!
Expand Down
16 changes: 7 additions & 9 deletions api/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const users: User[] = [
* Get user by ID
* BUG: This function doesn't handle the case when user is not found
*/
export function getUserById(id: number): User {
export function getUserById(id: number): User | undefined {
const user = users.find(u => u.id === id);
// TypeError will occur here when user is undefined
return user;
Expand All @@ -32,10 +32,10 @@ export function getUserById(id: number): User {
* Get user's email
* BUG: Accessing property on potentially undefined result
*/
export function getUserEmail(userId: number): string {
export function getUserEmail(userId: number): string | undefined {
const user = getUserById(userId);
// This will throw TypeError if user doesn't exist
return user.email;
return user?.email;
}

/**
Expand All @@ -45,22 +45,20 @@ export function getUserEmail(userId: number): string {
export function isAdmin(userId: number): boolean {
const user = getUserById(userId);
// Another potential TypeError here
return user.role === 'admin';
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)
}
4 changes: 2 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
26 changes: 13 additions & 13 deletions src/helpers/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,21 @@ class Logger {
}

// Missing JSDoc comment
debug(message: string, ...args: any[]): void {
debug(message: string, ...args: unknown[]): void {
if (this.shouldLog(LogLevel.DEBUG)) {
console.log(this.formatMessage('DEBUG', message), ...args);
}
}

// Missing JSDoc comment
info(message: string, ...args: any[]): void {
info(message: string, ...args: unknown[]): void {
if (this.shouldLog(LogLevel.INFO)) {
console.info(this.formatMessage('INFO', message), ...args);
}
}

// Missing JSDoc comment
warn(message: string, ...args: any[]): void {
warn(message: string, ...args: unknown[]): void {
if (this.shouldLog(LogLevel.WARN)) {
console.warn(this.formatMessage('WARN', message), ...args);
}
Expand Down Expand Up @@ -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;
}
}

Expand Down
72 changes: 17 additions & 55 deletions src/utils/messyCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,93 +4,55 @@
*/

// 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: unknown) {
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: unknown): unknown {
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);
function _fetchDataCallback(callback: (data: string) => void) {
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;
Expand Down
Loading