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): add defaultProject for project service #8815

Conversation

JoshuaKGoldberg
Copy link
Member

@JoshuaKGoldberg JoshuaKGoldberg commented Apr 1, 2024

PR Checklist

Overview

Adds a defaultProject property to the existing ProjectServiceOptions config object. Folks should be able to use it like:

EXPERIMENTAL_useProjectService: {
  allowDefaultProjectForFiles: ["./*.js"],
  defaultProject: "./tsconfig.json"
}

...except, I can't find an API to use the default project in the project service. Filing as a draft for reference while I ask about it. Chatted with @jakebailey and @sandersn in the TypeScript Discord. service.setCompilerOptionsForInferredProjects is the right API. Thanks!

❤️‍🔥

@typescript-eslint
Copy link
Contributor

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 https://opencollective.com/typescript-eslint.

Copy link

netlify bot commented Apr 1, 2024

Deploy Preview for typescript-eslint ready!

Name Link
🔨 Latest commit 33776db
🔍 Latest deploy log https://app.netlify.com/sites/typescript-eslint/deploys/661d207870ef8e0009fd296f
😎 Deploy Preview https://deploy-preview-8815--typescript-eslint.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 99 (no change from production)
Accessibility: 100 (no change from production)
Best Practices: 92 (no change from production)
SEO: 98 (no change from production)
PWA: 80 (no change from production)
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify site configuration.

@@ -58,6 +60,40 @@ export function createProjectService(
jsDocParsingMode,
});

if (typeof options === 'object' && options.defaultProject) {
try {
const configRead = tsserver.readConfigFile(
Copy link
Member Author

Choose a reason for hiding this comment

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

Fun fact: ts.readConfigFile has two unhappy paths:

  • If the config file is valid JSON but not right for TypeScript, it returns an object
  • If the config file is invalid JSON, it throws

🙌 error handling!

Copy link

codecov bot commented Apr 1, 2024

Codecov Report

Attention: Patch coverage is 90.00000% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 88.01%. Comparing base (ecb6b55) to head (3c64b54).
Report is 43 commits behind head on main.

❗ Current head 3c64b54 differs from pull request most recent head 33776db. Consider uploading reports for the commit 33776db to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8815      +/-   ##
==========================================
- Coverage   88.02%   88.01%   -0.02%     
==========================================
  Files         405      405              
  Lines       14089    14099      +10     
  Branches     4125     4127       +2     
==========================================
+ Hits        12402    12409       +7     
- Misses       1382     1385       +3     
  Partials      305      305              
Flag Coverage Δ
unittest 88.01% <90.00%> (-0.02%) ⬇️

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

Files Coverage Δ
...-estree/src/create-program/createProjectService.ts 77.27% <90.00%> (-6.07%) ⬇️

@JoshuaKGoldberg JoshuaKGoldberg marked this pull request as ready for review April 1, 2024 20:57
configRead.error,
{
getCurrentDirectory: system.getCurrentDirectory,
getCanonicalFileName: fileName => fileName,
Copy link
Member Author

Choose a reason for hiding this comment

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

I couldn't figure out a way to get this to execute in tests. 🤷

@JoshuaKGoldberg JoshuaKGoldberg added this to the 8.0.0 milestone Apr 4, 2024
bradzacher
bradzacher previously approved these changes Apr 15, 2024
Copy link
Member

@bradzacher bradzacher left a comment

Choose a reason for hiding this comment

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

packages/typescript-estree/src/parser-options.ts Outdated Show resolved Hide resolved
Co-authored-by: Brad Zacher <brad.zacher@gmail.com>
@JoshuaKGoldberg JoshuaKGoldberg merged commit 5542aeb into typescript-eslint:main Apr 15, 2024
57 checks passed
@JoshuaKGoldberg JoshuaKGoldberg deleted the project-service-default-project branch April 15, 2024 13:39
JoshuaKGoldberg added a commit that referenced this pull request Apr 19, 2024
* feat(eslint-plugin): remove formatting/layout rules

* Remove "layout"

* feat(typescript-estree): add defaultProject for project service (#8815)

* feat(typescript-estree): add defaultProject for project service

* Thanks Jake, service.setCompilerOptionsForInferredProjects

* Cleaned up a bit and added happy path testing

* Update packages/typescript-estree/src/parser-options.ts

Co-authored-by: Brad Zacher <brad.zacher@gmail.com>

---------

Co-authored-by: Brad Zacher <brad.zacher@gmail.com>

* feat(eslint-plugin): replace `no-new-symbol` with `no-new-native-nonconstructor` (#8895)

Co-authored-by: Brad Zacher <brad.zacher@gmail.com>

* Add tombstones

* 'deprecated' typo

* Let's mention both issues

* Fix unused variable issue

---------

Co-authored-by: Brad Zacher <brad.zacher@gmail.com>
Co-authored-by: Dave <reduckted@outlook.com>
JoshuaKGoldberg added a commit that referenced this pull request Apr 22, 2024
* feat(eslint-plugin): remove formatting/layout rules

* Remove "layout"

* feat(typescript-estree): add defaultProject for project service (#8815)

* feat(typescript-estree): add defaultProject for project service

* Thanks Jake, service.setCompilerOptionsForInferredProjects

* Cleaned up a bit and added happy path testing

* Update packages/typescript-estree/src/parser-options.ts

Co-authored-by: Brad Zacher <brad.zacher@gmail.com>

---------

Co-authored-by: Brad Zacher <brad.zacher@gmail.com>

* feat(eslint-plugin): replace `no-new-symbol` with `no-new-native-nonconstructor` (#8895)

Co-authored-by: Brad Zacher <brad.zacher@gmail.com>

* Add tombstones

* 'deprecated' typo

* Let's mention both issues

* Fix unused variable issue

---------

Co-authored-by: Brad Zacher <brad.zacher@gmail.com>
Co-authored-by: Dave <reduckted@outlook.com>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: Project service doesn't infer compilerOptions for files not included in a tsconfig.json
2 participants