Skip to content
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

feat(typescript-estree): allow providing code as a ts.SourceFile #5892


Copy link

@JoshuaKGoldberg JoshuaKGoldberg commented Oct 26, 2022

PR Checklist


Changes several function parameters from code: string to code: string | ts.SourceFile. Folks should now be able to pass in a source file directly, instead of the text of a file that we then have to redundantly reparse.

Targeting the v6 branch even though this arguably isn't really a breaking change. Since this is such a core API, I'd want it to be able to benefit from the v6 testing process too.

Copy link

Thanks for the PR, @JoshuaKGoldberg!

typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community.

The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately.

Thanks again!

🙏 Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently on As a thank you, your profile/company logo will be added to our main README which receives thousands of unique visitors per day.

Copy link

nx-cloud bot commented Oct 26, 2022

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 10cf653. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this branch

✅ Successfully ran 46 targets

Sent with 💌 from NxCloud.

Copy link

codecov bot commented Oct 26, 2022

Codecov Report

Merging #5892 (10cf653) into v6 (c446386) will increase coverage by 0.33%.
The diff coverage is 90.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##               v6    #5892      +/-   ##
+ Coverage   91.35%   91.68%   +0.33%     
  Files         364      356       -8     
  Lines       12132    12021     -111     
  Branches     3533     3523      -10     
- Hits        11083    11022      -61     
+ Misses        750      701      -49     
+ Partials      299      298       -1     
Flag Coverage Δ
unittest 91.68% <90.00%> (+0.33%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...estree/src/create-program/createIsolatedProgram.ts 76.00% <ø> (ø)
...ript-estree/src/create-program/createSourceFile.ts 77.77% <50.00%> (-9.73%) ⬇️ 95.31% <75.00%> (-1.52%) ⬇️
packages/typescript-estree/src/ast-converter.ts 100.00% <100.00%> (ø)
...-estree/src/create-program/createDefaultProgram.ts 78.26% <100.00%> (ø) 83.88% <100.00%> (+5.82%) ⬆️
packages/typescript-estree/src/source-files.ts 100.00% <100.00%> (ø)
packages/typescript-estree/src/convert.ts 97.85% <0.00%> (-0.06%) ⬇️
packages/typescript-estree/src/version-check.ts 100.00% <0.00%> (ø)
... and 16 more

@JoshuaKGoldberg JoshuaKGoldberg marked this pull request as ready for review November 3, 2022 13:44
options?: ParserOptions,
): ParseForESLintResult['ast'] {
return parseForESLint(code, options).ast;

function parseForESLint(
code: string,
code: string | ts.SourceFile,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI @Quramy - is there anything else you'd need/want done to help with the use case described in #774?

cc @mhartington - you were showing me using Quramy's language service plugin. I'm betting this will speed it up ever so slightly (though I'd be surprised if file parsing was a major bottleneck). ✨

@bradzacher bradzacher merged commit 9affa2a into typescript-eslint:v6 Nov 16, 2022
35 checks passed
@JoshuaKGoldberg JoshuaKGoldberg deleted the parse-for-eslint-ts-source-file branch November 16, 2022 13:28
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 24, 2022
@JoshuaKGoldberg JoshuaKGoldberg added this to the 6.0.0 milestone Dec 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet
None yet

Successfully merging this pull request may close these issues.

None yet

2 participants