Summary
AI-generated code has distinctive anti-patterns that differ from human-written code. Add a new AIPatternsAnalyzer that detects these.
AI Code Anti-Patterns to Detect
1. Magic Numbers
AI loves magic numbers instead of named constants:
# AI-generated
if confidence > 0.85:
retry(max_attempts=3, delay=2.5)
# Human-written
HIGH_CONFIDENCE_THRESHOLD = 0.85
MAX_RETRIES = 3
RETRY_DELAY_SECONDS = 2.5
2. Comment-Over-Code Ratio
AI tends to over-document obvious code:
# Initialize an empty list to store the results
results = []
# Loop through each item in the items list
for item in items:
# Append the item to the results list
results.append(item)
3. Over-Engineering
AI wraps simple logic in unnecessary abstractions:
class DataProcessorFactory:
@staticmethod
def create_processor(type: str) -> DataProcessor:
# For a simple list filter...
4. Uniform Variable Names
AI tends to use result, data, item, value without descriptive names.
5. TODO/Placeholder Comments
AI leaves # TODO: implement this, # Add more error handling here, pass
Implementation
- Create
ai_trust_validator/analyzers/ai_patterns.py
- Implement
AIPatternsAnalyzer(BaseAnalyzer)
- Add heuristics with configurable thresholds
- Add to
Validator._init_analyzers()
- Add comprehensive tests
Acceptance Criteria
Difficulty
Intermediate — pattern matching is straightforward but designing good heuristics requires thought.
Summary
AI-generated code has distinctive anti-patterns that differ from human-written code. Add a new
AIPatternsAnalyzerthat detects these.AI Code Anti-Patterns to Detect
1. Magic Numbers
AI loves magic numbers instead of named constants:
2. Comment-Over-Code Ratio
AI tends to over-document obvious code:
3. Over-Engineering
AI wraps simple logic in unnecessary abstractions:
4. Uniform Variable Names
AI tends to use
result,data,item,valuewithout descriptive names.5. TODO/Placeholder Comments
AI leaves
# TODO: implement this,# Add more error handling here,passImplementation
ai_trust_validator/analyzers/ai_patterns.pyAIPatternsAnalyzer(BaseAnalyzer)Validator._init_analyzers()Acceptance Criteria
Difficulty
Intermediate — pattern matching is straightforward but designing good heuristics requires thought.