Skip to content

Commit 6377e33

Browse files
committed
chore: use globby to improve git ignore file handling
1 parent 88f3ad6 commit 6377e33

File tree

4 files changed

+16
-62
lines changed

4 files changed

+16
-62
lines changed

Diff for: bun.lockb

1.47 KB
Binary file not shown.

Diff for: package.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nivalis/linter",
3-
"version": "0.0.8",
3+
"version": "0.0.10",
44
"module": "src/index.ts",
55
"type": "module",
66
"publishConfig": {
@@ -59,8 +59,7 @@
5959
"dependencies": {
6060
"@biomejs/js-api": "^0.6.2",
6161
"eslint": "^9.11.0",
62-
"fast-glob": "^3.3.2",
63-
"ignore": "^6.0.2",
62+
"globby": "^14.0.2",
6463
"yargs": "^17.7.2"
6564
}
6665
}

Diff for: src/biome.ts

+4-14
Original file line numberDiff line numberDiff line change
@@ -268,21 +268,11 @@ export const lintWithBiome = async (
268268
performance.mark("biome-start");
269269
}
270270

271-
const {stream, filter} = getFilesToLint(patterns);
272-
273-
const biomeResults: ESLint.LintResult[] = [];
274-
275-
for await (const file of stream) {
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);
283-
biomeResults.push(result);
284-
}
271+
const files = await getFilesToLint(patterns);
285272

273+
const biomeResults: ESLint.LintResult[] = await Promise.all(
274+
files.map(async (file) => await biomeLintFile(biome, config, file, fix, unsafe)),
275+
);
286276

287277
if (debug) {
288278
performance.mark("biome-end");

Diff for: src/files.ts

+10-45
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,11 @@
1-
import path from "node:path";
2-
import ignore from 'ignore'
3-
import fs from "node:fs";
4-
import fg from "fast-glob";
5-
6-
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-
23-
const globPatterns = patterns.flatMap((pattern) => {
24-
if (!fs.existsSync(pattern)) {
25-
return pattern;
26-
}
27-
28-
const stats = fs.lstatSync(pattern);
29-
30-
if (stats.isDirectory()) {
31-
return path.join(pattern, "**/*.{js,jsx,ts,tsx}");
32-
}
33-
34-
if (stats.isFile()) {
35-
return pattern;
36-
}
37-
38-
return [];
39-
});
40-
41-
return {stream: fg.stream(globPatterns, { dot: false, absolute: true, ignore:
42-
ignorePatterns
43-
}),
44-
filter: ig.createFilter()
45-
};
1+
import {globby} from 'globby';
2+
3+
export const getFilesToLint = async (patterns: string[]) => {
4+
return await globby(patterns, {
5+
gitignore: true,
6+
absolute: true,
7+
expandDirectories: {
8+
extensions: ['js', 'jsx', 'ts', 'tsx'],
9+
},
10+
});
4611
};

0 commit comments

Comments
 (0)