@@ -2,17 +2,30 @@ import { eslintRulesExtra } from "./official-eslint-rules.cjs"
22import { pluginImportRulesExtra , pluginImportTypeScriptRulesExtra } from "./plugin-import-rules.cjs"
33import { pluginNodeRules } from "./plugin-node-rules.cjs"
44import makeSynchronous from "make-synchronous"
5- import { findOneFile } from "./utils.cjs"
5+ import { findFilesForGroups } from "./utils.cjs"
66import type { GlobifiedEntry } from "globify-gitignore"
77import { Linter } from "eslint"
88
99const tsFiles = [ "**/*.tsx" , "**/*.ts" , "**/*.mts" , "**/*.cts" ]
10- const project = [ "**/tsconfig.json" , "!**/node_modules/**/tsconfig.json" ]
10+ const tscConfigFiles = [ "**/tsconfig.json" , "!**/node_modules/**/tsconfig.json" ]
1111
12- function globifyGitIgnoreFileWithDeps ( cwd : string , include : boolean ) {
13- // eslint-disable-next-line @typescript-eslint/no-var-requires
14- const { globifyGitIgnoreFile } = require ( "globify-gitignore" ) as typeof import ( "globify-gitignore" ) // prettier-ignore
15- return globifyGitIgnoreFile ( cwd , include )
12+ async function globifyGitIgnoreFileWithDeps ( cwd : string , include : boolean ) {
13+ try {
14+ // import in the function to allow makeSynchronous to work
15+ /* eslint-disable @typescript-eslint/no-var-requires */
16+ const { globifyGitIgnoreFile } = require ( "globify-gitignore" ) as typeof import ( "globify-gitignore" ) // prettier-ignore
17+ const { existsSync } = require ( "fs" ) as typeof import ( "fs" )
18+ const { join } = require ( "path" ) as typeof import ( "path" )
19+ /* eslint-enable @typescript-eslint/no-var-requires */
20+
21+ if ( ! existsSync ( join ( cwd , ".gitignore" ) ) ) {
22+ return [ ]
23+ }
24+ return await globifyGitIgnoreFile ( cwd , include )
25+ } catch ( error ) {
26+ console . error ( error )
27+ return [ ]
28+ }
1629}
1730const globifyGitIgnoreFileSync = makeSynchronous ( globifyGitIgnoreFileWithDeps ) as (
1831 cwd : string ,
@@ -41,18 +54,10 @@ function disableProjectBasedRules() {
4154 )
4255
4356 // check if there are any ts files
44- const hasTsFile = findOneFile ( cwd , tsFiles , ignore )
45-
46- // return if there are no ts files
47- if ( ! hasTsFile ) {
48- return true
49- }
50-
51- // check if there is a tsconfig.json file
52- const hasTsConfig = findOneFile ( cwd , project , ignore )
57+ const [ hasTscConfig , hasTsFile ] = findFilesForGroups ( cwd , tscConfigFiles , tsFiles , ignore )
5358
5459 // if there is no tsconfig.json file, but there are ts files, disable the project-based rules
55- const disable = ! hasTsConfig && hasTsFile
60+ const disable = ! hasTscConfig && hasTsFile
5661
5762 if ( disable ) {
5863 console . warn (
@@ -119,7 +124,7 @@ export const tsConfig: Linter.ConfigOverride<Linter.RulesRecord> = {
119124 files : tsFiles ,
120125 parser : "@typescript-eslint/parser" ,
121126 parserOptions : {
122- project,
127+ project : tscConfigFiles ,
123128 createDefaultProgram : true , // otherwise Eslint will error if a ts file is not covered by one of the tsconfig.json files
124129 } ,
125130 plugins : [ "@typescript-eslint" , "node" , "import" , "only-warn" ] ,
0 commit comments