Skip to content

Commit c8de80d

Browse files
ashleyshawclaude
andcommitted
feat: add .mustacheignore pattern support with glob matching
- Load ignore patterns from .mustacheignore file - Support simple paths, directory prefixes, and glob patterns - Add comprehensive test coverage for pattern matching - Update scanDirectory to respect ignore patterns 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
1 parent 6b93f5a commit c8de80d

File tree

2 files changed

+323
-164
lines changed

2 files changed

+323
-164
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* Tests for scan utilities
3+
*/
4+
const fs = require('fs');
5+
const path = require('path');
6+
const {
7+
loadIgnorePatterns,
8+
shouldIgnorePath,
9+
} = require('../scan');
10+
11+
describe('loadIgnorePatterns', () => {
12+
const tempDir = path.join(__dirname, 'temp-ignore-test');
13+
const ignorePath = path.join(tempDir, '.mustacheignore');
14+
15+
beforeEach(() => {
16+
if (!fs.existsSync(tempDir)) {
17+
fs.mkdirSync(tempDir, { recursive: true });
18+
}
19+
});
20+
21+
afterEach(() => {
22+
if (fs.existsSync(ignorePath)) {
23+
fs.unlinkSync(ignorePath);
24+
}
25+
if (fs.existsSync(tempDir)) {
26+
fs.rmdirSync(tempDir);
27+
}
28+
});
29+
30+
test('returns empty array when .mustacheignore does not exist', () => {
31+
const patterns = loadIgnorePatterns(tempDir);
32+
expect(patterns).toEqual([]);
33+
});
34+
35+
test('loads patterns from .mustacheignore file', () => {
36+
fs.writeFileSync(ignorePath, 'node_modules/\nbuild/\n# comment\n\ndocs/');
37+
const patterns = loadIgnorePatterns(tempDir);
38+
expect(patterns).toEqual(['node_modules/', 'build/', 'docs/']);
39+
});
40+
41+
test('shouldIgnorePath matches simple patterns', () => {
42+
const patterns = ['node_modules/', 'build/'];
43+
expect(shouldIgnorePath('node_modules/package', patterns)).toBe(true);
44+
expect(shouldIgnorePath('src/index.js', patterns)).toBe(false);
45+
});
46+
47+
test('shouldIgnorePath matches glob patterns', () => {
48+
const patterns = ['**/*.test.js', 'src/experimental/**'];
49+
expect(shouldIgnorePath('src/utils/scan.test.js', patterns)).toBe(true);
50+
expect(shouldIgnorePath('src/experimental/feature.js', patterns)).toBe(true);
51+
expect(shouldIgnorePath('src/utils/scan.js', patterns)).toBe(false);
52+
});
53+
});

0 commit comments

Comments
 (0)