Enhance refactor commands with controller-aware Route() updates and fix code quality violations
Add semantic token highlighting for 'that' variable and comment file references in VS Code extension Add Phone_Text_Input and Currency_Input components with formatting utilities Implement client widgets, form standardization, and soft delete functionality Add modal scroll lock and update documentation Implement comprehensive modal system with form integration and validation Fix modal component instantiation using jQuery plugin API Implement modal system with responsive sizing, queuing, and validation support Implement form submission with validation, error handling, and loading states Implement country/state selectors with dynamic data loading and Bootstrap styling Revert Rsx::Route() highlighting in Blade/PHP files Target specific PHP scopes for Rsx::Route() highlighting in Blade Expand injection selector for Rsx::Route() highlighting Add custom syntax highlighting for Rsx::Route() and Rsx.Route() calls Update jqhtml packages to v2.2.165 Add bundle path validation for common mistakes (development mode only) Create Ajax_Select_Input widget and Rsx_Reference_Data controller Create Country_Select_Input widget with default country support Initialize Tom Select on Select_Input widgets Add Tom Select bundle for enhanced select dropdowns Implement ISO 3166 geographic data system for country/region selection Implement widget-based form system with disabled state support 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -119,18 +119,40 @@ class DefensiveCoding_CodeQualityRule extends CodeQualityRule_Abstract
|
||||
}
|
||||
}
|
||||
|
||||
// Pattern 4: Guard clauses like: Rsx && Rsx.method()
|
||||
if (preg_match('/(\w+)\s*&&\s*\1\.\w+/i', $line, $matches)) {
|
||||
// Pattern 4: Guard clauses like: Rsx && Rsx.method() or component && component.val
|
||||
if (preg_match('/\b(\w+)\s*&&\s*\1\.\w+/i', $line, $matches)) {
|
||||
$variable = $matches[1];
|
||||
|
||||
|
||||
// Skip common boolean variable patterns
|
||||
if (!preg_match('/^(is|has|can|should|will|did|was)[A-Z]/', $variable)) {
|
||||
$fix_message = "DETECTED PATTERN: if ({$variable} && {$variable}.method)\n\n" .
|
||||
"This pattern has TWO possible meanings:\n" .
|
||||
"1. DEFENSIVE CODING (violation): Checking for something that MUST exist\n" .
|
||||
"2. DUCK TYPING (acceptable): Checking for optional capabilities\n\n" .
|
||||
"FOR LLM AGENTS - YOU MUST NOT DECIDE:\n" .
|
||||
"This rule requires human judgment. You MUST:\n" .
|
||||
"1. Analyze the context and determine which scenario applies\n" .
|
||||
"2. Present BOTH options:\n" .
|
||||
" - If defensive: Remove check, let it fail loud\n" .
|
||||
" - If duck typing: Use 'in' operator: if ('method' in {$variable})\n" .
|
||||
"3. Provide your recommendation with reasoning\n" .
|
||||
"4. WAIT for user decision\n" .
|
||||
"5. NEVER apply a fix without user confirmation\n\n" .
|
||||
"EXAMPLES:\n\n" .
|
||||
"DEFENSIVE CODING (remove the check):\n" .
|
||||
" if (Rsx && Rsx.Route(...)) // BAD - Rsx is core, must exist\n" .
|
||||
" if (component && component.render()) // BAD if render is required method\n\n" .
|
||||
"DUCK TYPING (use 'in' operator):\n" .
|
||||
" if (component && component.val) // Change to: if ('val' in component)\n" .
|
||||
" if (obj && obj.serialize) // Change to: if ('serialize' in obj)\n\n" .
|
||||
"NOTE: Core guaranteed classes (Rsx, Modal, Jqhtml_Component, etc.) should NEVER be checked - let failures happen loudly during development.";
|
||||
|
||||
$this->add_violation(
|
||||
$file_path,
|
||||
$line_number,
|
||||
"Defensive coding violation: Guard clause checking if '{$variable}' exists. All classes and variables must be assumed to exist. Code should fail loudly if something is undefined.",
|
||||
trim($line),
|
||||
"Remove the guard clause. Use '{$variable}.method()' directly.",
|
||||
$fix_message,
|
||||
'high'
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user