Fix LayoutLocalAssets rule to only check CSS and JS files

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
root
2025-10-30 22:57:19 +00:00
parent dbc5e6de1c
commit 0fef8539f4

View File

@@ -18,7 +18,7 @@ class LayoutLocalAssets_CodeQualityRule extends CodeQualityRule_Abstract
public function get_description(): string
{
return 'Enforces that local assets in layout files are included via bundle definitions, not hardcoded link/script tags';
return 'Enforces that local CSS and JavaScript files in layout files are included via bundle definitions, not hardcoded <link rel="stylesheet"> or <script src> tags';
}
public function get_file_patterns(): array
@@ -71,8 +71,25 @@ class LayoutLocalAssets_CodeQualityRule extends CodeQualityRule_Abstract
foreach ($lines as $line_num => $line) {
$line_number = $line_num + 1;
// Check for <link rel="stylesheet" with local href
if (preg_match('/<link\s+[^>]*href=["\'](\/[^"\']*)["\'][^>]*>/i', $line, $matches)) {
// Check for <link rel="stylesheet" with local href (CSS only, not favicons or other link types)
if (preg_match('/<link\s+[^>]*rel=["\']stylesheet["\'][^>]*href=["\'](\/[^"\']*)["\'][^>]*>/i', $line, $matches)) {
$href = $matches[1];
// Skip if it's a CDN/external URL (contains http)
if (str_contains(strtolower($line), 'http')) {
continue;
}
$violations[] = [
'type' => 'local_css',
'line' => $line_number,
'code' => trim($line),
'path' => $href
];
}
// Also check reversed attribute order: href before rel
if (preg_match('/<link\s+[^>]*href=["\'](\/[^"\']*)["\'][^>]*rel=["\']stylesheet["\'][^>]*>/i', $line, $matches)) {
$href = $matches[1];
// Skip if it's a CDN/external URL (contains http)