Skip to content

Commit 5841cde

Browse files
Added list of patterns fast glob should ignore
1 parent 3cbaa4f commit 5841cde

3 files changed

Lines changed: 44 additions & 6 deletions

File tree

src/test/parseFilePatterns.test.ts

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { parseFilePatterns } from "../util/parseFilePatterns.js";
66
import type { CLI } from "../types.js";
77

88
suite("parseFilePatterns", () => {
9-
test("returns explicit files as absolute paths", async () => {
9+
test("Returns explicit files as absolute paths", async () => {
1010
const directory = await createTempDirectory();
1111
const cwd = process.cwd();
1212

@@ -23,7 +23,7 @@ suite("parseFilePatterns", () => {
2323
}
2424
});
2525

26-
test("expands directories and filters by supported endings", async () => {
26+
test("Expands directories and filters by supported endings", async () => {
2727
const directory = await createTempDirectory();
2828
const cwd = process.cwd();
2929

@@ -50,7 +50,35 @@ suite("parseFilePatterns", () => {
5050
}
5151
});
5252

53-
test("expands glob patterns", async () => {
53+
test("Ignores hardcoded directories during directory expansion", async () => {
54+
const directory = await createTempDirectory();
55+
const cwd = process.cwd();
56+
57+
try {
58+
await fs.mkdir(path.join(directory, "nested"));
59+
await fs.mkdir(path.join(directory, "node_modules"));
60+
await fs.writeFile(
61+
path.join(directory, "nested", "one.txt"),
62+
"one",
63+
);
64+
await fs.writeFile(
65+
path.join(directory, "node_modules", "ignored.txt"),
66+
"ignored",
67+
);
68+
process.chdir(directory);
69+
70+
const files = await parseFilePatterns(createCLI(), ["."]);
71+
72+
assert.deepEqual(files, [
73+
path.join(directory, "nested", "one.txt"),
74+
]);
75+
} finally {
76+
process.chdir(cwd);
77+
await cleanupDirectory(directory);
78+
}
79+
});
80+
81+
test("Expands glob patterns", async () => {
5482
const directory = await createTempDirectory();
5583
const cwd = process.cwd();
5684

@@ -76,7 +104,7 @@ suite("parseFilePatterns", () => {
76104
}
77105
});
78106

79-
test("expands Windows-style glob patterns on Windows", async function () {
107+
test("Expands Windows-style glob patterns on Windows", async function () {
80108
if (path.sep !== "\\") {
81109
this.skip();
82110
return;
@@ -107,7 +135,7 @@ suite("parseFilePatterns", () => {
107135
}
108136
});
109137

110-
test("deduplicates overlapping patterns", async () => {
138+
test("Deduplicates overlapping patterns", async () => {
111139
const directory = await createTempDirectory();
112140
const cwd = process.cwd();
113141

@@ -127,7 +155,7 @@ suite("parseFilePatterns", () => {
127155
}
128156
});
129157

130-
test("rejects symbolic links", async function () {
158+
test("Rejects symbolic links", async function () {
131159
const directory = await createTempDirectory();
132160
const cwd = process.cwd();
133161

src/util/constants.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,11 @@ export const EXIT_ERROR = 2;
77

88
export const DEFAULT_INDENT_WIDTH = 4;
99
export const DEFAULT_LINE_WIDTH = 80;
10+
11+
export const GLOB_IGNORE_PATTERNS = [
12+
"**/.git/**",
13+
"**/.svn/**",
14+
"**/.hg/**",
15+
"**/node_modules/**",
16+
"**/__pycache__/**",
17+
];

src/util/parseFilePatterns.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { Options } from "fast-glob";
22
import fastGlob from "fast-glob";
33
import * as path from "node:path";
44
import type { CLI } from "../types.js";
5+
import { GLOB_IGNORE_PATTERNS } from "./constants.js";
56
import { lstatSafe } from "./lstatSafe.js";
67
import { normalizeToPosix } from "./normalizeToPosix.js";
78

@@ -15,6 +16,7 @@ export async function parseFilePatterns(
1516
const globOptions: Options = {
1617
dot: true,
1718
followSymbolicLinks: false,
19+
ignore: GLOB_IGNORE_PATTERNS,
1820
};
1921

2022
for (const pattern of filePatterns) {

0 commit comments

Comments
 (0)