Files
rspade_system/app/RSpade/CodeQuality/Rules/Jqhtml/JqhtmlRedundantClass_CodeQualityRule.php
root 77b4d10af8 Refactor filename naming system and apply convention-based renames
Standardize settings file naming and relocate documentation files
Fix code quality violations from rsx:check
Reorganize user_management directory into logical subdirectories
Move Quill Bundle to core and align with Tom Select pattern
Simplify Site Settings page to focus on core site information
Complete Phase 5: Multi-tenant authentication with login flow and site selection
Add route query parameter rule and synchronize filename validation logic
Fix critical bug in UpdateNpmCommand causing missing JavaScript stubs
Implement filename convention rule and resolve VS Code auto-rename conflict
Implement js-sanitizer RPC server to eliminate 900+ Node.js process spawns
Implement RPC server architecture for JavaScript parsing
WIP: Add RPC server infrastructure for JS parsing (partial implementation)
Update jqhtml terminology from destroy to stop, fix datagrid DOM preservation
Add JQHTML-CLASS-01 rule and fix redundant class names
Improve code quality rules and resolve violations
Remove legacy fatal error format in favor of unified 'fatal' error type
Filter internal keys from window.rsxapp output
Update button styling and comprehensive form/modal documentation
Add conditional fly-in animation for modals
Fix non-deterministic bundle compilation

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-13 19:10:02 +00:00

112 lines
3.8 KiB
PHP
Executable File

<?php
namespace App\RSpade\CodeQuality\Rules\Jqhtml;
use App\RSpade\CodeQuality\Rules\CodeQualityRule_Abstract;
/**
* JQHTML Redundant Class Rule
*
* Detects when a component's class name is redundantly specified in the class
* attribute of the Define tag. Component names are automatically added to the
* rendered element's class list, so explicitly including them is unnecessary.
*/
class JqhtmlRedundantClass_CodeQualityRule extends CodeQualityRule_Abstract
{
/**
* Get the unique identifier for this rule
*/
public function get_id(): string
{
return 'JQHTML-CLASS-01';
}
/**
* Get the human-readable name of this rule
*/
public function get_name(): string
{
return 'JQHTML Redundant Component Class Name';
}
/**
* Get the description of what this rule checks
*/
public function get_description(): string
{
return 'Detects when component class name is redundantly specified in class attribute';
}
/**
* Get file patterns this rule should check
*/
public function get_file_patterns(): array
{
return ['*.jqhtml'];
}
/**
* Get the default severity level
*/
public function get_default_severity(): string
{
return 'medium';
}
/**
* Check the file for violations
*/
public function check(string $file_path, string $contents, array $metadata = []): void
{
$lines = explode("\n", $contents);
$line_number = 0;
foreach ($lines as $line) {
$line_number++;
// Look for <Define:ComponentName ... class="..."> patterns
// Match Define tag with component name and class attribute on same line
if (preg_match('/<Define:([a-zA-Z_][a-zA-Z0-9_]*)\s+[^>]*class=["\']([^"\']*)["\']/', $line, $matches)) {
$component_name = $matches[1];
$class_attribute = $matches[2];
// Check if component name appears in the class attribute
// Use word boundary to avoid false positives (e.g., "Client" in "Client_Selector")
if (preg_match('/\b' . preg_quote($component_name, '/') . '\b/', $class_attribute)) {
$this->add_violation(
$file_path,
$line_number,
"Redundant class name '{$component_name}' in Define tag class attribute",
trim($line),
"Remove '{$component_name}' from the class attribute. Component names are automatically added to the rendered element's class list by the jqhtml framework. Explicitly including the component name in the class attribute is unnecessary.\n\n" .
"CURRENT:\n" .
" <Define:{$component_name} class=\"{$class_attribute}\">\n\n" .
"CORRECTED:\n" .
" <Define:{$component_name} class=\"" . $this->remove_component_from_class($class_attribute, $component_name) . "\">",
'medium'
);
}
}
}
}
/**
* Remove component name from class attribute string
*
* @param string $class_attribute The class attribute value
* @param string $component_name The component name to remove
* @return string The cleaned class attribute
*/
private function remove_component_from_class(string $class_attribute, string $component_name): string
{
// Remove the component name, handling multiple spaces
$cleaned = preg_replace('/\b' . preg_quote($component_name, '/') . '\b\s*/', '', $class_attribute);
// Clean up any double spaces
$cleaned = preg_replace('/\s+/', ' ', $cleaned);
// Trim leading/trailing spaces
return trim($cleaned);
}
}