Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
JoshuaKGoldberg merged 23 commits intotypescript-eslint:mainfromJoshuaKGoldberg:parser-options-project-trueFeb 10, 2023
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
23 commits Select commitHold shift + click to select a range
efec873
feat(typescript-estree): allow specifying project: true
JoshuaKGoldberg4927c39
Also fix unchanged file for lint I guess
JoshuaKGoldbergd01f2bf
Added docs
JoshuaKGoldberg4bf121e
More tsconfigRootDir: __dirname removal
JoshuaKGoldbergdb656f5
Added some unit tests
JoshuaKGoldberg003d993
you don't say
JoshuaKGoldbergeb34a95
Undo createWatchProgram.ts
JoshuaKGoldberg3a428c1
Merge branch 'main' into parser-options-project-true
JoshuaKGoldberg9ae3ce6
Added parse tests
JoshuaKGoldberg7cf6b80
Merge branch 'main' into parser-options-project-true
JoshuaKGoldberg3682aaf
Merge branch 'main'
JoshuaKGoldbergb024ad2
Fixed monorepos link
JoshuaKGoldberg6b16b04
Cache under all directories
JoshuaKGoldberg264a279
Added another test, just to be sure
JoshuaKGoldberg725603e
Merge branch 'main' into parser-options-project-true
JoshuaKGoldberg3c4850b
lint fix
JoshuaKGoldberg16e52d5
Add back tsconfigRootDir
JoshuaKGoldberg2be55de
Apply suggestions from code review
JoshuaKGoldbergfb6465c
Back to string |
JoshuaKGoldberge6df49a
Merge branch main and use ExpiringCache and idk what else git is hard
JoshuaKGoldbergedc11e5
Fix website build
JoshuaKGoldberg315bcde
Fix the build
JoshuaKGoldberg040a56a
A global tsconfigMatchCache, with a test
JoshuaKGoldbergFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
9 changes: 8 additions & 1 deletiondocs/architecture/Parser.mdx
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 |
---|---|---|
@@ -45,7 +45,7 @@ interface ParserOptions { | ||
lib?: string[]; | ||
moduleResolver?: string; | ||
program?: import('typescript').Program; | ||
project?: string | string[] | true; | ||
JoshuaKGoldberg marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
projectFolderIgnoreList?: string[]; | ||
tsconfigRootDir?: string; | ||
warnOnUnsupportedTypeScriptVersion?: boolean; | ||
@@ -188,6 +188,9 @@ This option allows you to provide a path to your project's `tsconfig.json`. **Th | ||
- Accepted values: | ||
```js | ||
// find the tsconfig.json nearest each source file | ||
project: true, | ||
// path | ||
project: './tsconfig.json'; | ||
@@ -198,6 +201,10 @@ This option allows you to provide a path to your project's `tsconfig.json`. **Th | ||
project: ['./packages/**/tsconfig.json', './separate-package/tsconfig.json']; | ||
``` | ||
- If `true`, each source file's parse will find the nearest `tsconfig.json` file to that source file. | ||
- This is done by checking that source file's directory tree for the nearest `tsconfig.json`. | ||
- If you use project references, TypeScript will not automatically use project references to resolve files. This means that you will have to add each referenced tsconfig to the `project` field either separately, or via a glob. | ||
- Note that using wide globs `**` in your `parserOptions.project` may cause performance implications. Instead of globs that use `**` to recursively check all folders, prefer paths that use a single `*` at a time. For more info see [#2611](https://github.com/typescript-eslint/typescript-eslint/issues/2611). | ||
5 changes: 3 additions & 2 deletionsdocs/architecture/TypeScript-ESTree.mdx
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
27 changes: 26 additions & 1 deletiondocs/linting/Typed_Linting.mdx
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
2 changes: 1 addition & 1 deletiondocs/linting/typed-linting/Monorepos.mdx
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
2 changes: 1 addition & 1 deletionpackages/types/src/parser-options.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
29 changes: 12 additions & 17 deletionspackages/typescript-estree/src/parseSettings/ExpiringCache.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
18 changes: 16 additions & 2 deletionspackages/typescript-estree/src/parseSettings/createParseSettings.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
59 changes: 59 additions & 0 deletionspackages/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 resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
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}'.`, | ||
); | ||
} |
6 changes: 6 additions & 0 deletionspackages/typescript-estree/src/parseSettings/index.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
5 changes: 3 additions & 2 deletionspackages/typescript-estree/src/parser-options.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
1 change: 1 addition & 0 deletionspackages/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 deletionspackages/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 deletionspackages/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 deletionspackages/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 deletionspackages/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.
Uh oh!
There was an error while loading.Please reload this page.
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.