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:
@@ -65,10 +65,18 @@ class JQueryVariableNaming_CodeQualityRule extends CodeQualityRule_Abstract
|
|||||||
* jQuery methods that ALWAYS return scalar values
|
* jQuery methods that ALWAYS return scalar values
|
||||||
*/
|
*/
|
||||||
private const SCALAR_METHODS = [
|
private const SCALAR_METHODS = [
|
||||||
'index', 'size', 'length', 'get', 'toArray',
|
'index', 'size', 'get', 'toArray',
|
||||||
'serialize', 'serializeArray',
|
'serialize', 'serializeArray',
|
||||||
'is', 'hasClass', 'is_visible' // Custom RSpade methods
|
'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
|
public function check(string $file_path, string $contents, array $metadata = []): void
|
||||||
{
|
{
|
||||||
@@ -216,12 +224,21 @@ class JQueryVariableNaming_CodeQualityRule extends CodeQualityRule_Abstract
|
|||||||
if (empty($chain)) {
|
if (empty($chain)) {
|
||||||
return 'jquery'; // No methods means original jQuery object
|
return 'jquery'; // No methods means original jQuery object
|
||||||
}
|
}
|
||||||
|
|
||||||
// Array access [0] or [index] returns DOM element (scalar)
|
// Array access [0] or [index] returns DOM element (scalar)
|
||||||
if (preg_match('/^\[[\d]+\]/', $chain)) {
|
if (preg_match('/^\[[\d]+\]/', $chain)) {
|
||||||
return 'scalar';
|
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
|
// Find the last method call in the chain
|
||||||
// Match patterns like .method() or .method(args)
|
// Match patterns like .method() or .method(args)
|
||||||
// Also capture what's inside the parentheses
|
// Also capture what's inside the parentheses
|
||||||
|
|||||||
@@ -59,7 +59,15 @@ class FilenameClassMatch_CodeQualityRule extends CodeQualityRule_Abstract
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if framework developer mode is enabled
|
||||||
|
$is_framework_developer = env('IS_FRAMEWORK_DEVELOPER', false);
|
||||||
|
|
||||||
foreach ($files as $file => $metadata) {
|
foreach ($files as $file => $metadata) {
|
||||||
|
// Skip backup/upstream files
|
||||||
|
if (str_ends_with($file, '.upstream') || str_ends_with($file, '.backup')) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Only check files in ./rsx or ./app/RSpade
|
// Only check files in ./rsx or ./app/RSpade
|
||||||
$is_rsx = str_starts_with($file, 'rsx/');
|
$is_rsx = str_starts_with($file, 'rsx/');
|
||||||
$is_rspade = str_starts_with($file, 'app/RSpade/');
|
$is_rspade = str_starts_with($file, 'app/RSpade/');
|
||||||
@@ -68,6 +76,11 @@ class FilenameClassMatch_CodeQualityRule extends CodeQualityRule_Abstract
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// app/RSpade/ files only checked in framework developer mode
|
||||||
|
if ($is_rspade && !$is_framework_developer) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$extension = $metadata['extension'] ?? '';
|
$extension = $metadata['extension'] ?? '';
|
||||||
$filename = basename($file);
|
$filename = basename($file);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user