Skip to content

Commit ca6070e

Browse files
authoredJun 22, 2024··
fix: use @eslint/config-array to resolve paths (#69)
1 parent 5b166c6 commit ca6070e

File tree

3 files changed

+75
-19
lines changed

3 files changed

+75
-19
lines changed
 

‎package.json

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
"eslint": "^8.50.0 || ^9.0.0"
3434
},
3535
"dependencies": {
36+
"@eslint/config-array": "^0.16.0",
37+
"@voxpelli/config-array-find-files": "^0.1.2",
3638
"bundle-require": "^5.0.0",
3739
"cac": "^6.7.14",
3840
"chokidar": "^3.6.0",

‎pnpm-lock.yaml

+41
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/configs.ts

+32-19
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { dirname, resolve } from 'node:path'
1+
import { dirname, relative, resolve } from 'node:path'
22
import process from 'node:process'
3+
import { ConfigArray } from '@eslint/config-array'
4+
import { configArrayFindFiles } from '@voxpelli/config-array-find-files'
35
import { bundleRequire } from 'bundle-require'
4-
import fg from 'fast-glob'
56
import { findUp } from 'find-up'
67
import c from 'picocolors'
78
import { resolve as resolveModule } from 'mlly'
@@ -208,28 +209,39 @@ export async function readConfig(
208209
}
209210
}
210211

212+
const noopSchema = {
213+
merge: 'replace',
214+
validate() {},
215+
}
216+
217+
const flatConfigNoopSchema = {
218+
settings: noopSchema,
219+
linterOptions: noopSchema,
220+
language: noopSchema,
221+
languageOptions: noopSchema,
222+
processor: noopSchema,
223+
plugins: noopSchema,
224+
rules: noopSchema,
225+
}
226+
211227
export async function globMatchedFiles(
212228
basePath: string,
213229
configs: FlatConfigItem[],
214230
): Promise<MatchedFile[]> {
215231
console.log(MARK_INFO, 'Globing matched files')
216-
const files = await fg(
217-
configs.flatMap(i => i.files ?? []).filter(i => typeof i === 'string') as string[],
218-
{
219-
cwd: basePath,
220-
onlyFiles: true,
221-
ignore: [
222-
'**/node_modules/**',
223-
'**/dist/**',
224-
'**/.git/**',
225-
...configs
226-
.filter(i => isIgnoreOnlyConfig(i))
227-
.flatMap(i => i.ignores ?? [])
228-
.filter(i => typeof i === 'string') as string[],
229-
],
230-
deep: 5, // TODO: maybe increase this?
231-
},
232-
)
232+
233+
const configArray = new ConfigArray(configs, {
234+
basePath,
235+
schema: flatConfigNoopSchema,
236+
})
237+
238+
await configArray.normalize()
239+
240+
const files = await configArrayFindFiles({
241+
basePath,
242+
configs: configArray,
243+
})
244+
233245
files.sort()
234246

235247
const ignoreOnlyConfigs = configs.filter(isIgnoreOnlyConfig)
@@ -245,6 +257,7 @@ export async function globMatchedFiles(
245257

246258
return files
247259
.map((filepath) => {
260+
filepath = relative(basePath, filepath)
248261
const result = matchFile(filepath, configs, ignoreOnlyConfigs)
249262
if (!result.configs.length)
250263
return undefined

0 commit comments

Comments
 (0)
Please sign in to comment.