52 lines
1.8 KiB
Plaintext
52 lines
1.8 KiB
Plaintext
---
|
|
description: Low Line of Code patterns and conventions for maintainable code structure and readability for src/**/* and other relevant directories
|
|
alwaysApply: false
|
|
---
|
|
# File Size Limit Rule
|
|
|
|
## Core Principles
|
|
- **Readability**: Smaller files are easier to understand and navigate
|
|
- **Maintainability**: Limited scope makes files easier to maintain
|
|
- **Single Responsibility**: Encourages proper separation of concerns
|
|
|
|
## Implementation Patterns
|
|
|
|
### File Organization
|
|
```python
|
|
# ✅ DO: Split large files into focused modules
|
|
# auth_service.py - Authentication logic only
|
|
class AuthService:
|
|
# 50-100 lines of focused authentication code
|
|
pass
|
|
|
|
# user_service.py - User management logic only
|
|
class UserService:
|
|
# 50-100 lines of focused user management code
|
|
pass
|
|
```
|
|
|
|
### Anti-Patterns
|
|
```python
|
|
# ❌ DON'T: Create monolithic files with multiple responsibilities
|
|
# massive_service.py - 500+ lines mixing multiple concerns
|
|
class MassiveService:
|
|
# Authentication methods
|
|
def authenticate_user(self): pass
|
|
def validate_token(self): pass
|
|
|
|
# User management methods
|
|
def create_user(self): pass
|
|
def update_user(self): pass
|
|
|
|
# Email functionality
|
|
def send_email(self): pass
|
|
def format_email(self): pass
|
|
|
|
# And many more unrelated methods...
|
|
```
|
|
### File Line Limit Rule (Format)
|
|
```markdown
|
|
- **Keep each code file under 300 lines of code (LOC)** to ensure readability, maintainability, and modularity.
|
|
- **Exceed 300 LOC only in exceptional cases**—up to a hard maximum of 350 LOC—when there is a clear, well-documented justification (e.g., improved clarity, essential functionality, or a meaningful reduction in complexity elsewhere).
|
|
- **Before exceeding 300 LOC**, always assess whether splitting or refactoring the file would lead to a more maintainable and organized codebase.
|
|
``` |