fix: resolve CI linting errors
Some checks failed
CI / test (3.10) (push) Failing after 10s
CI / test (3.11) (push) Failing after 10s
CI / test (3.12) (push) Failing after 10s
CI / build (push) Has been cancelled
CI / lint (push) Has been cancelled

This commit is contained in:
2026-02-02 14:59:33 +00:00
parent 75e00a4aaa
commit 94818f5226

View File

@@ -21,15 +21,22 @@ class IssueDetector:
SECURITY_PATTERNS = [ SECURITY_PATTERNS = [
{ {
'pattern': r'(?i)(sql\s*\(|execute\s*\(|exec\s*\(|SELECT\s+|UPDATE\s+|INSERT\s+|DELETE\s+)', 'pattern': (
r'(?i)(sql\\s*\\(|execute\\s*\\(|exec\\s*\\(|SELECT\\s+|UPDATE\\s+|'
r'INSERT\\s+|DELETE\\s+)'
),
'type': 'sql_injection', 'type': 'sql_injection',
'severity': 'critical', 'severity': 'critical',
'title': 'Potential SQL Injection', 'title': 'Potential SQL Injection',
'description': 'String concatenation or interpolation used in SQL query', 'description': (
'suggestion': 'Use parameterized queries or ORM methods instead of string concatenation', 'String concatenation or interpolation used in SQL query'
),
'suggestion': (
'Use parameterized queries or ORM methods instead of string concatenation'
),
}, },
{ {
'pattern': r'(?i)(innerHTML\s*=|outerHTML\s*=|document\.write\s*\()', 'pattern': r'(?i)(innerHTML\\s*=|outerHTML\\s*=|document\\.write\\s*\\()',
'type': 'xss', 'type': 'xss',
'severity': 'critical', 'severity': 'critical',
'title': 'Potential XSS Vulnerability', 'title': 'Potential XSS Vulnerability',
@@ -37,7 +44,7 @@ class IssueDetector:
'suggestion': 'Use textContent or sanitize HTML before insertion', 'suggestion': 'Use textContent or sanitize HTML before insertion',
}, },
{ {
'pattern': r'(?i)(eval\s*\(|setTimeout\s*\(\s*['"]|setInterval\s*\(\s*['"])', 'pattern': r'(?i)(eval\\s*\\(|setTimeout\\s*\\(\\s*[\\'\\"]|setInterval\\s*\\(\\s*[\\'\\"])',
'type': 'code_injection', 'type': 'code_injection',
'severity': 'critical', 'severity': 'critical',
'title': 'Code Injection Risk', 'title': 'Code Injection Risk',
@@ -45,7 +52,7 @@ class IssueDetector:
'suggestion': 'Avoid eval() and dynamic code execution when possible', 'suggestion': 'Avoid eval() and dynamic code execution when possible',
}, },
{ {
'pattern': r'(?i)(os\.system\s*\(|subprocess\.|shell=True|popen)', 'pattern': r'(?i)(os\\.system\\s*\\(|subprocess\\.|shell=True|popen)',
'type': 'command_injection', 'type': 'command_injection',
'severity': 'critical', 'severity': 'critical',
'title': 'Command Injection Risk', 'title': 'Command Injection Risk',
@@ -53,7 +60,7 @@ class IssueDetector:
'suggestion': 'Use subprocess with shell=False and validate/sanitize inputs', 'suggestion': 'Use subprocess with shell=False and validate/sanitize inputs',
}, },
{ {
'pattern': r'(?i)(password\s*=|passwd\s*=|secret\s*=|token\s*=|api_key\s*=)', 'pattern': r'(?i)(password\\s*=|passwd\\s*=|secret\\s*=|token\\s*=|api_key\\s*=)',
'type': 'hardcoded_secret', 'type': 'hardcoded_secret',
'severity': 'high', 'severity': 'high',
'title': 'Hardcoded Secret Detected', 'title': 'Hardcoded Secret Detected',
@@ -69,7 +76,7 @@ class IssueDetector:
'suggestion': 'Use HTTPS for all network communications', 'suggestion': 'Use HTTPS for all network communications',
}, },
{ {
'pattern': r'(?i)(random\.randint\s*\(|random\.random\s*\()', 'pattern': r'(?i)(random\\.randint\\s*\\(|random\\.random\\s*\\()',
'type': 'weak_crypto', 'type': 'weak_crypto',
'severity': 'medium', 'severity': 'medium',
'title': 'Weak Random Number Generator', 'title': 'Weak Random Number Generator',
@@ -80,7 +87,7 @@ class IssueDetector:
BUG_PATTERNS = [ BUG_PATTERNS = [
{ {
'pattern': r'(?i)(if\s*\([^)]*==[^)]*\)\s*:|if\s*\([^)]*=\s*[^)]*\)\s*:)', 'pattern': r'(?i)(if\\s*\\([^)]*==[^)]*\\)\\s*:|if\\s*\\([^)]*=\\s*[^)]*\\)\\s*:)',
'type': 'assignment_in_condition', 'type': 'assignment_in_condition',
'severity': 'high', 'severity': 'high',
'title': 'Assignment in Condition', 'title': 'Assignment in Condition',
@@ -88,7 +95,7 @@ class IssueDetector:
'suggestion': 'Use == for comparison, not =', 'suggestion': 'Use == for comparison, not =',
}, },
{ {
'pattern': r'(?i)(\bNone\b.*==|==.*\bNone\b)', 'pattern': r'(?i)(\\bNone\\b.*==|==.*\\bNone\\b)',
'type': 'none_comparison', 'type': 'none_comparison',
'severity': 'medium', 'severity': 'medium',
'title': 'Direct None Comparison', 'title': 'Direct None Comparison',
@@ -96,7 +103,7 @@ class IssueDetector:
'suggestion': 'Use "is None" for None comparisons in Python', 'suggestion': 'Use "is None" for None comparisons in Python',
}, },
{ {
'pattern': r'\bexcept\s*:\s*$', 'pattern': r'\\bexcept\\s*:\\s*$',
'type': 'bare_except', 'type': 'bare_except',
'severity': 'medium', 'severity': 'medium',
'title': 'Bare Except Clause', 'title': 'Bare Except Clause',
@@ -104,7 +111,7 @@ class IssueDetector:
'suggestion': 'Catch specific exceptions or at least Exception', 'suggestion': 'Catch specific exceptions or at least Exception',
}, },
{ {
'pattern': r'(?i)(\.get\s*\(\s*['"]?\s*['"]?\s*\))', 'pattern': r'(?i)(\\.get\\s*\\(\\s*[\\'\\"]?\\s*[\\'\\"]?\\s*\\))',
'type': 'unused_get', 'type': 'unused_get',
'severity': 'low', 'severity': 'low',
'title': 'Dictionary get() with no default', 'title': 'Dictionary get() with no default',
@@ -115,7 +122,7 @@ class IssueDetector:
CODE_SMELL_PATTERNS = [ CODE_SMELL_PATTERNS = [
{ {
'pattern': r'^\s*for\s+.*\s+in\s+.*:\s*$', 'pattern': r'^\\s*for\\s+.*\\s+in\\s+.*:\\s*$',
'type': 'long_loop', 'type': 'long_loop',
'severity': 'low', 'severity': 'low',
'title': 'Complex Loop', 'title': 'Complex Loop',
@@ -123,7 +130,7 @@ class IssueDetector:
'suggestion': 'Consider using list comprehensions or vectorized operations', 'suggestion': 'Consider using list comprehensions or vectorized operations',
}, },
{ {
'pattern': r'(?i)(\bTODO\b|\bFIXME\b|\bHACK\b|\bXXX\b)', 'pattern': r'(?i)(\\bTODO\\b|\\bFIXME\\b|\\bHACK\\b|\\bXXX\\b)',
'type': 'code_tag', 'type': 'code_tag',
'severity': 'low', 'severity': 'low',
'title': 'Code Tag Found', 'title': 'Code Tag Found',
@@ -131,7 +138,7 @@ class IssueDetector:
'suggestion': 'Address the TODO or create a ticket to track it', 'suggestion': 'Address the TODO or create a ticket to track it',
}, },
{ {
'pattern': r'(?i)(\bprint\s*\(|console\.log\s*\()', 'pattern': r'(?i)(\\bprint\\s*\\(|console\\.log\\s*\\()',
'type': 'debug_statement', 'type': 'debug_statement',
'severity': 'low', 'severity': 'low',
'title': 'Debug Statement', 'title': 'Debug Statement',
@@ -147,7 +154,7 @@ class IssueDetector:
'suggestion': 'Split long lines for better readability', 'suggestion': 'Split long lines for better readability',
}, },
{ {
'pattern': r'\bpass\b', 'pattern': r'\\bpass\\b',
'type': 'empty_block', 'type': 'empty_block',
'severity': 'low', 'severity': 'low',
'title': 'Empty Code Block', 'title': 'Empty Code Block',
@@ -192,7 +199,9 @@ class IssueDetector:
return issues return issues
def detect_diff_issues(self, old_code: str, new_code: str, language: str = "text") -> list[Issue]: def detect_diff_issues(
self, old_code: str, new_code: str, language: str = "text"
) -> list[Issue]:
"""Detect issues specifically in the diff (added/modified lines).""" """Detect issues specifically in the diff (added/modified lines)."""
issues = [] issues = []
new_lines = new_code.splitlines() new_lines = new_code.splitlines()