Skip to content

Commit 88f3ad6

Browse files
committed
chore: add support for gitignores
1 parent 5f86a72 commit 88f3ad6

File tree

4 files changed

+32
-7
lines changed

4 files changed

+32
-7
lines changed

Diff for: bun.lockb

388 Bytes
Binary file not shown.

Diff for: package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nivalis/linter",
3-
"version": "0.0.7",
3+
"version": "0.0.8",
44
"module": "src/index.ts",
55
"type": "module",
66
"publishConfig": {
@@ -60,6 +60,7 @@
6060
"@biomejs/js-api": "^0.6.2",
6161
"eslint": "^9.11.0",
6262
"fast-glob": "^3.3.2",
63+
"ignore": "^6.0.2",
6364
"yargs": "^17.7.2"
6465
}
6566
}

Diff for: src/biome.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -268,13 +268,18 @@ export const lintWithBiome = async (
268268
performance.mark("biome-start");
269269
}
270270

271-
const stream = getFilesToLint(patterns);
271+
const {stream, filter} = getFilesToLint(patterns);
272272

273273
const biomeResults: ESLint.LintResult[] = [];
274274

275275
for await (const file of stream) {
276-
console.log(file);
277-
const result = await biomeLintFile(biome, config, file as string, fix, unsafe);
276+
const filePath = file as string;
277+
278+
if (!filter(path.relative(process.cwd(), filePath))) {
279+
continue;
280+
}
281+
282+
const result = await biomeLintFile(biome, config, filePath, fix, unsafe);
278283
biomeResults.push(result);
279284
}
280285

Diff for: src/files.ts

+22-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,25 @@
11
import path from "node:path";
2+
import ignore from 'ignore'
23
import fs from "node:fs";
34
import fg from "fast-glob";
45

56
export const getFilesToLint = (patterns: string[]) => {
7+
8+
const gitignore = path.join(process.cwd(), ".gitignore");
9+
const ignorePatterns: string[] = [".git"];
10+
11+
if (fs.existsSync(gitignore)) {
12+
const gitignoreContent = fs.readFileSync(gitignore, "utf8");
13+
const lines = gitignoreContent
14+
.split("\n")
15+
.map((line) => line.trim())
16+
.filter((line) => line && !line.startsWith("#") && !line.startsWith("!"));
17+
18+
ignorePatterns.push(...lines);
19+
}
20+
21+
const ig = ignore().add(ignorePatterns);
22+
623
const globPatterns = patterns.flatMap((pattern) => {
724
if (!fs.existsSync(pattern)) {
825
return pattern;
@@ -21,7 +38,9 @@ export const getFilesToLint = (patterns: string[]) => {
2138
return [];
2239
});
2340

24-
return fg.stream(globPatterns, { dot: true, absolute: true, ignore:
25-
["node_modules/**", "**/node_modules/**"]
26-
});
41+
return {stream: fg.stream(globPatterns, { dot: false, absolute: true, ignore:
42+
ignorePatterns
43+
}),
44+
filter: ig.createFilter()
45+
};
2746
};

0 commit comments

Comments
 (0)