Fix Blade files in directory detection (#509)

* Fix Blade directory detection

AI assistance: Codex reproduced the issue, implemented the fix, and ran the validation described in the pull request.

* Fix compound scan suffix matching

AI assistance: Codex addressed review findings and ran the validation described in the pull request.
This commit is contained in:
Paul Bakaus
2026-08-04 14:08:49 -07:00
committed by GitHub
parent 2f609915eb
commit 80e4dd0d58
3 changed files with 37 additions and 4 deletions
+24 -2
View File
@@ -6,7 +6,7 @@ import { spawnSync } from 'child_process';
import {
ANTIPATTERNS, checkElementBorders, checkElementMotion, checkElementGlow, isNeutralColor, isFullPage,
detectText, detectHtml, extractStyleBlocks, extractCSSinJS,
walkDir, SCANNABLE_EXTENSIONS,
walkDir, hasScannableExtension, SCANNABLE_EXTENSIONS,
buildImportGraph, resolveImport,
detectFrameworkConfig, isPortListening, FRAMEWORK_CONFIGS,
} from '../cli/engine/detect-antipatterns.mjs';
@@ -2071,10 +2071,32 @@ describe('walkDir', () => {
expect(SCANNABLE_EXTENSIONS.has('.sass')).toBe(true);
});
test('finds Blade templates during directory scans', () => {
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'impeccable-walk-'));
try {
const blade = path.join(tmp, 'resources', 'views', 'card.blade.php');
const upperBlade = path.join(tmp, 'resources', 'views', 'hero.BLADE.PHP');
fs.mkdirSync(path.dirname(blade), { recursive: true });
fs.writeFileSync(blade, '<div class="bg-orange-900 text-gray-500">Card</div>');
fs.writeFileSync(upperBlade, '<div>Hero</div>');
expect(walkDir(tmp)).toEqual(expect.arrayContaining([blade, upperBlade]));
} finally {
fs.rmSync(tmp, { recursive: true, force: true });
}
});
test('compound suffix matching does not broaden scans to module extensions', () => {
expect(hasScannableExtension('card.blade.php')).toBe(true);
expect(hasScannableExtension('card.BLADE.PHP')).toBe(true);
for (const file of ['next.config.mjs', 'vite.config.cjs', 'route.mts', 'route.cts']) {
expect(hasScannableExtension(file)).toBe(false);
}
});
test('finds scannable files', () => {
const files = walkDir(FIXTURES);
expect(files.length).toBeGreaterThanOrEqual(3);
expect(files.every(f => SCANNABLE_EXTENSIONS.has(path.extname(f)))).toBe(true);
expect(files.every(hasScannableExtension)).toBe(true);
});
test('returns empty for nonexistent dir', () => {