Skip to content

Commit

Permalink
fix: use @eslint/config-array to resolve paths (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
voxpelli authored Jun 22, 2024
1 parent 5b166c6 commit ca6070e
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 19 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
"eslint": "^8.50.0 || ^9.0.0"
},
"dependencies": {
"@eslint/config-array": "^0.16.0",
"@voxpelli/config-array-find-files": "^0.1.2",
"bundle-require": "^5.0.0",
"cac": "^6.7.14",
"chokidar": "^3.6.0",
Expand Down
41 changes: 41 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 32 additions & 19 deletions src/configs.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { dirname, resolve } from 'node:path'
import { dirname, relative, resolve } from 'node:path'
import process from 'node:process'
import { ConfigArray } from '@eslint/config-array'
import { configArrayFindFiles } from '@voxpelli/config-array-find-files'
import { bundleRequire } from 'bundle-require'
import fg from 'fast-glob'
import { findUp } from 'find-up'
import c from 'picocolors'
import { resolve as resolveModule } from 'mlly'
Expand Down Expand Up @@ -208,28 +209,39 @@ export async function readConfig(
}
}

const noopSchema = {
merge: 'replace',
validate() {},
}

const flatConfigNoopSchema = {
settings: noopSchema,
linterOptions: noopSchema,
language: noopSchema,
languageOptions: noopSchema,
processor: noopSchema,
plugins: noopSchema,
rules: noopSchema,
}

export async function globMatchedFiles(
basePath: string,
configs: FlatConfigItem[],
): Promise<MatchedFile[]> {
console.log(MARK_INFO, 'Globing matched files')
const files = await fg(
configs.flatMap(i => i.files ?? []).filter(i => typeof i === 'string') as string[],
{
cwd: basePath,
onlyFiles: true,
ignore: [
'**/node_modules/**',
'**/dist/**',
'**/.git/**',
...configs
.filter(i => isIgnoreOnlyConfig(i))
.flatMap(i => i.ignores ?? [])
.filter(i => typeof i === 'string') as string[],
],
deep: 5, // TODO: maybe increase this?
},
)

const configArray = new ConfigArray(configs, {
basePath,
schema: flatConfigNoopSchema,
})

await configArray.normalize()

const files = await configArrayFindFiles({
basePath,
configs: configArray,
})

files.sort()

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

return files
.map((filepath) => {
filepath = relative(basePath, filepath)
const result = matchFile(filepath, configs, ignoreOnlyConfigs)
if (!result.configs.length)
return undefined
Expand Down

0 comments on commit ca6070e

Please sign in to comment.