-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat(typescript-estree): allow specifying project: true #6084
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
JoshuaKGoldberg
merged 23 commits into
typescript-eslint:main
from
JoshuaKGoldberg:parser-options-project-true
Feb 10, 2023
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
efec873
feat(typescript-estree): allow specifying project: true
JoshuaKGoldberg 4927c39
Also fix unchanged file for lint I guess
JoshuaKGoldberg d01f2bf
Added docs
JoshuaKGoldberg 4bf121e
More tsconfigRootDir: __dirname removal
JoshuaKGoldberg db656f5
Added some unit tests
JoshuaKGoldberg 003d993
you don't say
JoshuaKGoldberg eb34a95
Undo createWatchProgram.ts
JoshuaKGoldberg 3a428c1
Merge branch 'main' into parser-options-project-true
JoshuaKGoldberg 9ae3ce6
Added parse tests
JoshuaKGoldberg 7cf6b80
Merge branch 'main' into parser-options-project-true
JoshuaKGoldberg 3682aaf
Merge branch 'main'
JoshuaKGoldberg b024ad2
Fixed monorepos link
JoshuaKGoldberg 6b16b04
Cache under all directories
JoshuaKGoldberg 264a279
Added another test, just to be sure
JoshuaKGoldberg 725603e
Merge branch 'main' into parser-options-project-true
JoshuaKGoldberg 3c4850b
lint fix
JoshuaKGoldberg 16e52d5
Add back tsconfigRootDir
JoshuaKGoldberg 2be55de
Apply suggestions from code review
JoshuaKGoldberg fb6465c
Back to string |
JoshuaKGoldberg e6df49a
Merge branch main and use ExpiringCache and idk what else git is hard
JoshuaKGoldberg edc11e5
Fix website build
JoshuaKGoldberg 315bcde
Fix the build
JoshuaKGoldberg 040a56a
A global tsconfigMatchCache, with a test
JoshuaKGoldberg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
packages/typescript-estree/src/parseSettings/getProjectConfigFiles.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import debug from 'debug'; | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
|
||
import type { ParseSettings } from '.'; | ||
|
||
const log = debug('typescript-eslint:typescript-estree:getProjectConfigFiles'); | ||
|
||
/** | ||
* Checks for a matching TSConfig to a file including its parent directories, | ||
* permanently caching results under each directory it checks. | ||
* | ||
* @remarks | ||
* We don't (yet!) have a way to attach file watchers on disk, but still need to | ||
* cache file checks for rapid subsequent calls to fs.existsSync. See discussion | ||
* in https://github.com/typescript-eslint/typescript-eslint/issues/101. | ||
*/ | ||
export function getProjectConfigFiles( | ||
JoshuaKGoldberg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
parseSettings: Pick< | ||
ParseSettings, | ||
'filePath' | 'tsconfigMatchCache' | 'tsconfigRootDir' | ||
>, | ||
project: string | string[] | true | undefined, | ||
): string[] | undefined { | ||
if (project !== true) { | ||
return project === undefined || Array.isArray(project) | ||
? project | ||
: [project]; | ||
} | ||
|
||
log('Looking for tsconfig.json at or above file: %s', parseSettings.filePath); | ||
let directory = path.dirname(parseSettings.filePath); | ||
const checkedDirectories = [directory]; | ||
|
||
do { | ||
log('Checking tsconfig.json path: %s', directory); | ||
const tsconfigPath = path.join(directory, 'tsconfig.json'); | ||
const cached = | ||
parseSettings.tsconfigMatchCache.get(directory) ?? | ||
(fs.existsSync(tsconfigPath) && tsconfigPath); | ||
|
||
if (cached) { | ||
for (const directory of checkedDirectories) { | ||
parseSettings.tsconfigMatchCache.set(directory, cached); | ||
} | ||
return [cached]; | ||
} | ||
|
||
directory = path.dirname(directory); | ||
checkedDirectories.push(directory); | ||
} while ( | ||
directory.length > 1 && | ||
directory.length >= parseSettings.tsconfigRootDir.length | ||
); | ||
|
||
throw new Error( | ||
`project was set to \`true\` but couldn't find any tsconfig.json relative to '${parseSettings.filePath}' within '${parseSettings.tsconfigRootDir}'.`, | ||
); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
packages/typescript-estree/tests/fixtures/projectTrue/nested/deep/included.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
const b = true; |
1 change: 1 addition & 0 deletions
1
packages/typescript-estree/tests/fixtures/projectTrue/nested/included.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
const b = true; |
3 changes: 3 additions & 0 deletions
3
packages/typescript-estree/tests/fixtures/projectTrue/nested/tsconfig.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"include": ["."] | ||
} |
1 change: 1 addition & 0 deletions
1
packages/typescript-estree/tests/fixtures/projectTrue/notIncluded.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
const c = true; |
14 changes: 14 additions & 0 deletions
14
packages/typescript-estree/tests/lib/createParseSettings.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { createParseSettings } from '../../src/parseSettings/createParseSettings'; | ||
|
||
describe('createParseSettings', () => { | ||
describe('tsconfigMatchCache', () => { | ||
it('reuses the TSConfig match cache when called a subsequent time', () => { | ||
const parseSettings1 = createParseSettings('input.ts'); | ||
const parseSettings2 = createParseSettings('input.ts'); | ||
|
||
expect(parseSettings1.tsconfigMatchCache).toBe( | ||
parseSettings2.tsconfigMatchCache, | ||
); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.