File tree Expand file tree Collapse file tree 2 files changed +34
-3
lines changed Expand file tree Collapse file tree 2 files changed +34
-3
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import type { ParserOptions } from "@typescript-eslint/parser";
2
2
import type { ProgramOptions } from "./ts" ;
3
3
import { TSServiceManager } from "./ts" ;
4
4
import * as tsEslintParser from "@typescript-eslint/parser" ;
5
+ import { getProjectConfigFiles } from "./utils/get-project-config-files" ;
5
6
6
7
const DEFAULT_EXTRA_FILE_EXTENSIONS = [ ".vue" , ".svelte" , ".astro" ] ;
7
8
const tsServiceManager = new TSServiceManager ( ) ;
@@ -47,9 +48,7 @@ function* iterateOptions(options: ParserOptions): Iterable<ProgramOptions> {
47
48
"Specify `parserOptions.project`. Otherwise there is no point in using this parser."
48
49
) ;
49
50
}
50
- for ( const project of Array . isArray ( options . project )
51
- ? options . project
52
- : [ options . project ] ) {
51
+ for ( const project of getProjectConfigFiles ( options ) ) {
53
52
yield {
54
53
project,
55
54
filePath : options . filePath ,
Original file line number Diff line number Diff line change
1
+ import type { ParserOptions } from "@typescript-eslint/parser" ;
2
+ import fs from "fs" ;
3
+ import path from "path" ;
4
+
5
+ export function getProjectConfigFiles ( options : ParserOptions ) : string [ ] {
6
+ const tsconfigRootDir =
7
+ typeof options . tsconfigRootDir === "string"
8
+ ? options . tsconfigRootDir
9
+ : process . cwd ( ) ;
10
+ if ( options . project !== true ) {
11
+ return Array . isArray ( options . project )
12
+ ? options . project
13
+ : [ options . project ! ] ;
14
+ }
15
+
16
+ let directory = path . dirname ( options . filePath ! ) ;
17
+ const checkedDirectories = [ directory ] ;
18
+
19
+ do {
20
+ const tsconfigPath = path . join ( directory , "tsconfig.json" ) ;
21
+ if ( fs . existsSync ( tsconfigPath ) ) {
22
+ return [ tsconfigPath ] ;
23
+ }
24
+
25
+ directory = path . dirname ( directory ) ;
26
+ checkedDirectories . push ( directory ) ;
27
+ } while ( directory . length > 1 && directory . length >= tsconfigRootDir . length ) ;
28
+
29
+ throw new Error (
30
+ `project was set to \`true\` but couldn't find any tsconfig.json relative to '${ options . filePath } ' within '${ tsconfigRootDir } '.`
31
+ ) ;
32
+ }
You can’t perform that action at this time.
0 commit comments