# Code Conventions ## Language & Framework **Primary Language**: [Python / JavaScript / TypeScript / etc.] **Version**: [Version number] **Framework**: [Framework name and version] ## Code Style ### Naming Conventions **Variables & Functions**: - Style: [snake_case / camelCase / PascalCase] - Examples: `user_name`, `calculate_total`, `process_payment` **Classes**: - Style: [PascalCase / snake_case] - Examples: `UserService`, `PaymentProcessor`, `OrderRepository` **Constants**: - Style: [UPPER_SNAKE_CASE / camelCase] - Examples: `MAX_RETRIES`, `API_BASE_URL`, `DEFAULT_TIMEOUT` **Files**: - Style: [snake_case / kebab-case] - Examples: `user_service.py`, `payment-processor.ts` ### Formatting - **Line Length**: [80 / 100 / 120] characters maximum - **Indentation**: [2 / 4] spaces (no tabs) - **String Quotes**: [single / double / either] quotes - **Trailing Commas**: [required / optional / never] ## Type Safety **Type Hints/Annotations**: [Required / Encouraged / Optional] ```python # Example for Python def process_user(user_id: int, name: str) -> User: """Process user with given ID and name.""" pass ``` **Type Checking**: [Tool name: mypy / TypeScript / Flow / None] ## Documentation ### Docstrings **Style**: [Google / NumPy / Sphinx / JSDoc] **Required for**: - [ ] Public functions - [ ] Public classes - [ ] Modules - [ ] Complex algorithms **Example**: ```python def calculate_total(items: List[Item], tax_rate: float) -> Decimal: """ Calculate total price including tax. Args: items: List of items to total tax_rate: Tax rate as decimal (e.g., 0.08 for 8%) Returns: Total price including tax Raises: ValueError: If tax_rate is negative """ pass ``` ### Comments **When to Comment**: - Complex algorithms - Non-obvious business logic - Workarounds or hacks - TODOs and FIXMEs **What NOT to Comment**: - Self-explanatory code - What code does (let code be self-documenting) - Commented-out code (delete instead) ## Testing ### Test Coverage - **Minimum Coverage**: [85 / 90 / 95]% - **New Code Coverage**: [90 / 95 / 100]% ### Test Organization ``` tests/ ├── unit/ # Unit tests │ └── test_[module].py ├── integration/ # Integration tests │ └── test_[feature].py └── e2e/ # End-to-end tests └── test_[scenario].py ``` ### Test Naming Pattern: `test_[what]_[condition]_[expected]` Examples: - `test_user_creation_with_valid_data_succeeds` - `test_payment_processing_with_insufficient_funds_raises_error` - `test_order_total_calculation_with_discount_returns_correct_amount` ### Test Structure ```python def test_something(): # Arrange - Set up test data user = User(name="John") # Act - Perform the action result = process_user(user) # Assert - Verify results assert result.processed == True ``` ## Error Handling ### Exception Handling - **Custom Exceptions**: [Required / Optional] for domain errors - **Logging**: [Always / Sometimes / Never] log exceptions - **Re-raising**: [Wrap / Re-raise / Handle] exceptions appropriately **Example**: ```python try: result = risky_operation() except SpecificError as e: logger.error(f"Operation failed: {e}") raise DomainError("User-friendly message") from e ``` ## Git Conventions ### Commit Messages **Format**: [Conventional Commits / Custom / Free-form] ``` ():