# Development Guidelines ## Coding Conventions ### Naming Conventions #### Variables and Functions **TypeScript/JavaScript**: ```typescript // ✅ Good example const userProfileData = fetchUserProfile(); function calculateTotalPrice(items: CartItem[]): number { } // ❌ Bad example const data = fetch(); function calc(arr: any[]): number { } ``` **Principles**: - Variables: camelCase, noun or noun phrase - Functions: camelCase, start with a verb - Constants: UPPER_SNAKE_CASE - Boolean: start with `is`, `has`, or `should` #### Classes and Interfaces ```typescript // Class: PascalCase, noun class TaskManager { } class UserAuthenticationService { } // Interface: PascalCase, with or without the I prefix interface ITaskRepository { } interface Task { } // Type alias: PascalCase type TaskStatus = 'todo' | 'in_progress' | 'completed'; ``` ### Code Formatting **Indentation**: [2 spaces / 4 spaces / tabs] **Line length**: maximum [80/100/120] characters **Example**: ```typescript // [language] code formatting example [code example] ``` ### Comment Conventions **Function and class documentation**: ```typescript /** * Calculate the total number of tasks * * @param tasks - Array of tasks to count * @param filter - Filter condition (optional) * @returns Total number of tasks * @throws {ValidationError} When the task array is invalid */ function countTasks( tasks: Task[], filter?: TaskFilter ): number { // Implementation } ``` **Inline comments**: ```typescript // ✅ Good example: explain why you do it // Invalidate the cache to fetch the latest data cache.clear(); // ❌ Bad example: what you are doing (obvious from the code) // Clear the cache cache.clear(); ``` ### Error Handling **Principles**: - Expected errors: define an appropriate error class - Unexpected errors: propagate upward - Do not ignore errors **Example**: ```typescript // Error class definition class ValidationError extends Error { constructor( message: string, public field: string, public value: unknown ) { super(message); this.name = 'ValidationError'; } } // Error handling try { const task = await taskService.create(data); } catch (error) { if (error instanceof ValidationError) { console.error(`Validation error [${error.field}]: ${error.message}`); // Provide feedback to the user } else { console.error('Unexpected error:', error); throw error; // Propagate upward } } ``` ## Git Workflow Rules ### Branching Strategy **Branch types**: - `main`: ready to deploy to production - `develop`: latest development state - `feature/[feature-name]`: new feature development - `fix/[fix-description]`: bug fixes - `refactor/[target]`: refactoring **Flow**: ``` main └─ develop ├─ feature/task-management ├─ feature/user-auth └─ fix/task-validation ``` ### Commit Message Conventions **Format**: ``` ():