Fix JS-JQUERY-VAR-01 and MANIFEST-FILENAME-01 false positives

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
root
2025-12-26 03:49:09 +00:00
parent aac7585b8c
commit fd7d3340f4
2 changed files with 33 additions and 3 deletions

View File

@@ -65,10 +65,18 @@ class JQueryVariableNaming_CodeQualityRule extends CodeQualityRule_Abstract
* jQuery methods that ALWAYS return scalar values
*/
private const SCALAR_METHODS = [
'index', 'size', 'length', 'get', 'toArray',
'index', 'size', 'get', 'toArray',
'serialize', 'serializeArray',
'is', 'hasClass', 'is_visible' // Custom RSpade methods
];
/**
* jQuery properties (not methods) that return scalar values
* These are accessed without parentheses: $el.length, not $el.length()
*/
private const SCALAR_PROPERTIES = [
'length',
];
public function check(string $file_path, string $contents, array $metadata = []): void
{
@@ -216,12 +224,21 @@ class JQueryVariableNaming_CodeQualityRule extends CodeQualityRule_Abstract
if (empty($chain)) {
return 'jquery'; // No methods means original jQuery object
}
// Array access [0] or [index] returns DOM element (scalar)
if (preg_match('/^\[[\d]+\]/', $chain)) {
return 'scalar';
}
// Check if chain ENDS with a scalar property access (e.g., .length)
// Pattern: .property at end of chain (no parentheses, possibly followed by operators)
if (preg_match('/\.([a-zA-Z_][a-zA-Z0-9_]*)\s*(?:[|&+\-*\/%]|$|;)/', $chain, $prop_match)) {
$last_property = $prop_match[1];
if (in_array($last_property, self::SCALAR_PROPERTIES, true)) {
return 'scalar';
}
}
// Find the last method call in the chain
// Match patterns like .method() or .method(args)
// Also capture what's inside the parentheses