From ca6070e86bd6a5aa6f11cf1d9fc9bd0d9e956e97 Mon Sep 17 00:00:00 2001 From: Pelle Wessman Date: Sat, 22 Jun 2024 16:47:50 +0200 Subject: [PATCH] fix: use `@eslint/config-array` to resolve paths (#69) --- package.json | 2 ++ pnpm-lock.yaml | 41 ++++++++++++++++++++++++++++++++++++++++ src/configs.ts | 51 +++++++++++++++++++++++++++++++------------------- 3 files changed, 75 insertions(+), 19 deletions(-) diff --git a/package.json b/package.json index cf4ecb1..99c0851 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index cfef5e2..2f00068 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -11,6 +11,12 @@ importers: .: dependencies: + '@eslint/config-array': + specifier: ^0.16.0 + version: 0.16.0 + '@voxpelli/config-array-find-files': + specifier: ^0.1.2 + version: 0.1.2(@eslint/config-array@0.16.0) bundle-require: specifier: ^5.0.0 version: 5.0.0(esbuild@0.21.5) @@ -962,14 +968,26 @@ packages: resolution: {integrity: sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==} engines: {node: '>= 8'} + '@nodelib/fs.scandir@3.0.0': + resolution: {integrity: sha512-ktI9+PxfHYtKjF3cLTUAh2N+b8MijCRPNwKJNqTVdL0gB0QxLU2rIRaZ1t71oEa3YBDE6bukH1sR0+CDnpp/Mg==} + engines: {node: '>=16.14.0'} + '@nodelib/fs.stat@2.0.5': resolution: {integrity: sha512-RkhPPp2zrqDAQA/2jNhnztcPAlv64XdhIp7a7454A5ovI7Bukxgt7MX7udwAu3zg1DcpPU0rz3VV1SeaqvY4+A==} engines: {node: '>= 8'} + '@nodelib/fs.stat@3.0.0': + resolution: {integrity: sha512-2tQOI38s19P9i7X/Drt0v8iMA+KMsgdhB/dyPER+e+2Y8L1Z7QvnuRdW/uLuf5YRFUYmnj4bMA6qCuZHFI1GDQ==} + engines: {node: '>=16.14.0'} + '@nodelib/fs.walk@1.2.8': resolution: {integrity: sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==} engines: {node: '>= 8'} + '@nodelib/fs.walk@2.0.0': + resolution: {integrity: sha512-54voNDBobGdMl3BUXSu7UaDh1P85PGHWlJ5e0XhPugo1JulOyCtp2I+5ri4wplGDJ8QGwPEQW7/x3yTLU7yF1A==} + engines: {node: '>=16.14.0'} + '@npmcli/agent@2.2.2': resolution: {integrity: sha512-OrcNPXdpSl9UX7qPVRWbmWMCSXrcDa2M9DvrbOTj7ao1S4PlqVFYv9/yLKMkrJKZ/V5A/kDBC690or307i26Og==} engines: {node: ^16.14.0 || >=18.0.0} @@ -1754,6 +1772,12 @@ packages: '@volar/typescript@2.3.0': resolution: {integrity: sha512-PtUwMM87WsKVeLJN33GSTUjBexlKfKgouWlOUIv7pjrOnTwhXHZNSmpc312xgXdTjQPpToK6KXSIcKu9sBQ5LQ==} + '@voxpelli/config-array-find-files@0.1.2': + resolution: {integrity: sha512-jOva73R+0Nc5/pyS/piBSjQzO4EehME7rPSkBpPC9PYSta+yj3OpF14v0m0HLLYLVNuyHbBjQh5QvGIZwTH2eA==} + engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} + peerDependencies: + '@eslint/config-array': '>=0.16.0' + '@vue-macros/common@1.10.3': resolution: {integrity: sha512-YSgzcbXrRo8a/TF/YIguqEmTld1KA60VETKJG8iFuaAfj7j+Tbdin3cj7/cYbcCHORSq1v9IThgq7r8keH7LXQ==} engines: {node: '>=16.14.0'} @@ -6017,13 +6041,25 @@ snapshots: '@nodelib/fs.stat': 2.0.5 run-parallel: 1.2.0 + '@nodelib/fs.scandir@3.0.0': + dependencies: + '@nodelib/fs.stat': 3.0.0 + run-parallel: 1.2.0 + '@nodelib/fs.stat@2.0.5': {} + '@nodelib/fs.stat@3.0.0': {} + '@nodelib/fs.walk@1.2.8': dependencies: '@nodelib/fs.scandir': 2.1.5 fastq: 1.17.1 + '@nodelib/fs.walk@2.0.0': + dependencies: + '@nodelib/fs.scandir': 3.0.0 + fastq: 1.17.1 + '@npmcli/agent@2.2.2': dependencies: agent-base: 7.1.1 @@ -7229,6 +7265,11 @@ snapshots: path-browserify: 1.0.1 vscode-uri: 3.0.8 + '@voxpelli/config-array-find-files@0.1.2(@eslint/config-array@0.16.0)': + dependencies: + '@eslint/config-array': 0.16.0 + '@nodelib/fs.walk': 2.0.0 + '@vue-macros/common@1.10.3(rollup@3.29.4)(vue@3.4.29(typescript@5.5.2))': dependencies: '@babel/types': 7.24.7 diff --git a/src/configs.ts b/src/configs.ts index 3aea0ed..597eee7 100644 --- a/src/configs.ts +++ b/src/configs.ts @@ -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' @@ -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 { 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) @@ -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