fix: Resolve 21 ruff linting errors (SIM102, SIM117, B904, SIM113, B007)
Fixed all 21 linting errors identified in GitHub Actions: SIM102 (7 errors - nested if statements): - config_extractor.py:468 - Combined nested conditions - config_validator.py (was B904, already fixed) - pattern_recognizer.py:430,538,916 - Combined nested conditions - test_example_extractor.py:365,412,460 - Combined nested conditions - unified_skill_builder.py:1070 - Combined nested conditions SIM117 (9 errors - multiple with statements): - test_install_agent.py:418 - Combined with statements - test_issue_219_e2e.py:278 - Combined with statements - test_llms_txt_downloader.py:33,88 - Combined with statements - test_skip_llms_txt.py:75,98,121,148,172,304 - Combined with statements B904 (1 error - exception handling): - config_validator.py:62 - Added 'from e' to exception chain SIM113 (1 error - enumerate usage): - doc_scraper.py:1068 - Removed unused 'completed' counter variable B007 (1 error - unused loop variable): - pdf_scraper.py:167 - Changed 'keywords' to '_' for unused variable All changes improve code quality without altering functionality. Tests: 1214 passed, 167 skipped (4 pre-existing failures unrelated) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -427,13 +427,12 @@ class SingletonDetector(BasePatternDetector):
|
||||
for method in class_sig.methods:
|
||||
# Python: __init__ or __new__
|
||||
# Java/C#: private constructor (detected by naming)
|
||||
if method.name in ["__new__", "__init__", "constructor"]:
|
||||
# Check if it has logic (not just pass)
|
||||
if method.docstring or len(method.parameters) > 1:
|
||||
evidence.append(f"Controlled initialization: {method.name}")
|
||||
confidence += 0.3
|
||||
has_init_control = True
|
||||
break
|
||||
# Check if it has logic (not just pass)
|
||||
if method.name in ["__new__", "__init__", "constructor"] and (method.docstring or len(method.parameters) > 1):
|
||||
evidence.append(f"Controlled initialization: {method.name}")
|
||||
confidence += 0.3
|
||||
has_init_control = True
|
||||
break
|
||||
|
||||
# Check for class-level instance storage
|
||||
# This would require checking class attributes (future enhancement)
|
||||
@@ -535,10 +534,9 @@ class FactoryDetector(BasePatternDetector):
|
||||
factory_method_names = ["create", "make", "build", "new", "get"]
|
||||
for method in class_sig.methods:
|
||||
method_lower = method.name.lower()
|
||||
if any(name in method_lower for name in factory_method_names):
|
||||
# Check if method returns something (has return type or is not void)
|
||||
if method.return_type or "create" in method_lower:
|
||||
return PatternInstance(
|
||||
# Check if method returns something (has return type or is not void)
|
||||
if any(name in method_lower for name in factory_method_names) and (method.return_type or "create" in method_lower):
|
||||
return PatternInstance(
|
||||
pattern_type=self.pattern_type,
|
||||
category=self.category,
|
||||
confidence=0.6,
|
||||
@@ -913,16 +911,15 @@ class DecoratorDetector(BasePatternDetector):
|
||||
|
||||
# Check __init__ for composition (takes object parameter)
|
||||
init_method = next((m for m in class_sig.methods if m.name == "__init__"), None)
|
||||
if init_method:
|
||||
# Check if takes object parameter (not just self)
|
||||
if len(init_method.parameters) > 1: # More than just 'self'
|
||||
param_names = [p.name for p in init_method.parameters if p.name != "self"]
|
||||
if any(
|
||||
name in ["wrapped", "component", "inner", "obj", "target"]
|
||||
for name in param_names
|
||||
):
|
||||
evidence.append(f"Takes wrapped object in constructor: {param_names}")
|
||||
confidence += 0.4
|
||||
# Check if takes object parameter (not just self)
|
||||
if init_method and len(init_method.parameters) > 1: # More than just 'self'
|
||||
param_names = [p.name for p in init_method.parameters if p.name != "self"]
|
||||
if any(
|
||||
name in ["wrapped", "component", "inner", "obj", "target"]
|
||||
for name in param_names
|
||||
):
|
||||
evidence.append(f"Takes wrapped object in constructor: {param_names}")
|
||||
confidence += 0.4
|
||||
|
||||
if confidence >= 0.5:
|
||||
return PatternInstance(
|
||||
|
||||
Reference in New Issue
Block a user