diff --git a/.changeset/slow-jobs-confess.md b/.changeset/slow-jobs-confess.md new file mode 100644 index 0000000..b37fe36 --- /dev/null +++ b/.changeset/slow-jobs-confess.md @@ -0,0 +1,5 @@ +--- +"typescript-eslint-parser-for-extra-files": minor +--- + +feat: Support glob pattern in `options.project` diff --git a/package.json b/package.json index af8f00c..b6c5ea4 100644 --- a/package.json +++ b/package.json @@ -96,6 +96,7 @@ "eslint-plugin-svelte": "^2.11.0", "eslint-plugin-vue": "^9.6.0", "eslint-plugin-yml": "^1.2.0", + "glob": "^10.3.10", "mocha": "^10.0.0", "mocha-chai-jest-snapshot": "^1.1.3", "nyc": "^15.1.0", diff --git a/src/utils/get-project-config-files.ts b/src/utils/get-project-config-files.ts index 1fac0d7..28b08bc 100644 --- a/src/utils/get-project-config-files.ts +++ b/src/utils/get-project-config-files.ts @@ -1,16 +1,26 @@ import type { ParserOptions } from "@typescript-eslint/parser"; import fs from "fs"; +import { glob } from "glob"; import path from "path"; +function syncWithGlob(pattern: string, cwd: string): string[] { + return glob + .sync(pattern, { cwd }) + .map((filePath) => path.resolve(cwd, filePath)); +} + export function getProjectConfigFiles(options: ParserOptions): string[] { const tsconfigRootDir = typeof options.tsconfigRootDir === "string" ? options.tsconfigRootDir : process.cwd(); + if (options.project !== true) { return Array.isArray(options.project) - ? options.project - : [options.project!]; + ? options.project.flatMap((projectPattern: string) => + syncWithGlob(projectPattern, tsconfigRootDir), + ) + : syncWithGlob(options.project!, tsconfigRootDir); } let directory = path.dirname(options.filePath!);