fix: correct malformed JS-001 validation logic

Fixed broken conditional logic in JavaScript validation that was causing
false positives on every single line of JS files.

Problem:
- Malformed ternary expression with 'if' inside condition
- 'else True' caused every line WITHOUT 'window.apiClient' to trigger
- Result: 3,144 violations (mostly false positives)

Solution:
- Simplified conditional to check if 'window.apiClient' exists first
- Then check if it's not in a comment
- Clearer, more maintainable logic

Results:
- Before: 3,144 total violations (3,000+ false JS-001 violations)
- After: 184 total violations (all legitimate)
- JS-001 violations: 0 (correct - no actual window.apiClient usage)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-11-28 19:50:46 +01:00
parent c0794295e2
commit 1a5782f6c8

View File

@@ -469,22 +469,20 @@ class ArchitectureValidator:
# JS-001: Check for window.apiClient
for i, line in enumerate(lines, 1):
if (
"window.apiClient" in line
and "//" not in line[: line.find("window.apiClient")]
if "window.apiClient" in line
else True
):
self._add_violation(
rule_id="JS-001",
rule_name="Use apiClient directly",
severity=Severity.WARNING,
file_path=file_path,
line_number=i,
message="Use apiClient directly instead of window.apiClient",
context=line.strip(),
suggestion="Replace window.apiClient with apiClient",
)
if "window.apiClient" in line:
# Check if it's not in a comment
before_occurrence = line[: line.find("window.apiClient")]
if "//" not in before_occurrence:
self._add_violation(
rule_id="JS-001",
rule_name="Use apiClient directly",
severity=Severity.WARNING,
file_path=file_path,
line_number=i,
message="Use apiClient directly instead of window.apiClient",
context=line.strip(),
suggestion="Replace window.apiClient with apiClient",
)
# JS-002: Check for console usage
for i, line in enumerate(lines, 1):