| name | code-quality |
| description | Code quality review checklist and enforcement guide. KISS, DRY, YAGNI principles plus concrete code smells and their fixes. Use before marking any task complete. |
| metadata | {"tags":"quality, review, clean-code, refactoring, checklist","origin":"ECC coding-style + patterns (adapted for Antigravity)"} |
When to Use
- Before marking any task as complete
- During code review of your own or others' code
- When refactoring existing code
- When you notice code that "feels wrong"
Pre-Completion Checklist
Run through this before considering any feature done:
Correctness
Readability
Structure
Safety
Core Principles Applied
KISS — Keep It Simple
class LayerProcessorFactory:
def create_processor(self, strategy_type: str) -> LayerProcessor:
if strategy_type == "simple":
return SimpleLayerProcessor(SimpleStrategy())
...
def process_layer(layer: QgsVectorLayer) -> list[dict]:
return [feature.attributes() for feature in layer.getFeatures()]
DRY — Don't Repeat Yourself
def process_file(path):
if not path.exists():
raise FileNotFoundError(path)
...
def load_config(path):
if not path.exists():
raise FileNotFoundError(path)
...
def require_file(path: Path) -> Path:
if not path.exists():
raise FileNotFoundError(f"Required file not found: {path}")
return path
def process_file(path): require_file(path); ...
def load_config(path): require_file(path); ...
YAGNI — You Aren't Gonna Need It
class DataProcessor:
def process(self, data, strategy=None, plugin=None,
validator=None, transformer=None):
...
def process_data(data: list[dict]) -> list[dict]:
return [transform(item) for item in data if is_valid(item)]
Code Smells & Fixes
Deep Nesting → Early Returns
def handle_request(request):
if request:
if request.user:
if request.user.is_authenticated:
if request.data:
return process(request.data)
def handle_request(request):
if not request:
return None
if not request.user or not request.user.is_authenticated:
raise PermissionError("Authentication required")
if not request.data:
raise ValueError("Request data is required")
return process(request.data)
Magic Numbers → Named Constants
if layer.featureCount() > 50000:
use_chunked_processing()
MAX_FEATURES_IN_MEMORY = 50_000
if layer.featureCount() > MAX_FEATURES_IN_MEMORY:
use_chunked_processing()
Long Function → Decompose
def process_and_export_layer(layer, output_path, format, crs, fields):
def process_and_export_layer(layer, output_path, format, crs, fields):
validated = validate_layer(layer)
reprojected = reproject_to(validated, crs)
filtered = select_fields(reprojected, fields)
export_layer(filtered, output_path, format)
Mutable Default Argument (Python Gotcha)
def add_item(item, items=[]):
items.append(item)
return items
def add_item(item, items=None):
if items is None:
items = []
items.append(item)
return items
Refactoring Workflow
- Identify the smell — which rule above does it violate?
- Write a test first — ensure behaviour is captured before changing code
- Make the smallest change — one improvement at a time
- Run tests — verify nothing broke
- Commit — each refactor in its own commit:
refactor: extract validate_layer helper