From 1a5782f6c82461064c48d10763e4b0cc90cf8e63 Mon Sep 17 00:00:00 2001 From: Samir Boulahtit Date: Fri, 28 Nov 2025 19:50:46 +0100 Subject: [PATCH] fix: correct malformed JS-001 validation logic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- scripts/validate_architecture.py | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/scripts/validate_architecture.py b/scripts/validate_architecture.py index 55125df3..956251be 100755 --- a/scripts/validate_architecture.py +++ b/scripts/validate_architecture.py @@ -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):