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:
@@ -18,7 +18,7 @@ class LayoutLocalAssets_CodeQualityRule extends CodeQualityRule_Abstract
|
|||||||
|
|
||||||
public function get_description(): string
|
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
|
public function get_file_patterns(): array
|
||||||
@@ -71,8 +71,25 @@ class LayoutLocalAssets_CodeQualityRule extends CodeQualityRule_Abstract
|
|||||||
foreach ($lines as $line_num => $line) {
|
foreach ($lines as $line_num => $line) {
|
||||||
$line_number = $line_num + 1;
|
$line_number = $line_num + 1;
|
||||||
|
|
||||||
// Check for <link rel="stylesheet" with local href
|
// Check for <link rel="stylesheet" with local href (CSS only, not favicons or other link types)
|
||||||
if (preg_match('/<link\s+[^>]*href=["\'](\/[^"\']*)["\'][^>]*>/i', $line, $matches)) {
|
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];
|
$href = $matches[1];
|
||||||
|
|
||||||
// Skip if it's a CDN/external URL (contains http)
|
// Skip if it's a CDN/external URL (contains http)
|
||||||
|
|||||||
Reference in New Issue
Block a user