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): restrict variable declarator definite/init combinations#9228
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
feat(typescript-estree): restrict variable declarator definite/init combinations#9228
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Thanks for the PR,@Josh-Cena! 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 onhttps://opencollective.com/typescript-eslint. |
netlifybot commentedJun 3, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
✅ Deploy Preview fortypescript-eslint ready!
To edit notification comments on pull requests, go to yourNetlify site configuration. |
nx-cloudbot commentedJun 3, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
☁️ Nx Cloud ReportCI is running/has finished running commands for commitbe1b324. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this CI Pipeline Execution ✅ Successfully ran 2 targetsSent with 💌 fromNxCloud. |
16faace tocea3f68CompareThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Script for generating this pile of fixtures. Let me know if I should trim it down (especially the error combinations)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Nit: I wouldn't bother committing this - just leaving it as a note in the PR description should be enough for us to find it later if we want to reproduce this later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Ok but I designed this script to allow us to:
- Quickly identify error condition combinations
- Quickly move a bunch of fixtures around valid/invalid cases
- Quickly generate more combinations,
so I think overall it helps with maintenance
| "declaration/VariableDeclaration/fixtures/_error_/const-destructure-no-init/fixture.ts", | ||
| "declaration/VariableDeclaration/fixtures/_error_/const-destructure-type-no-init/fixture.ts", | ||
| "declaration/VariableDeclaration/fixtures/_error_/const-id-no-init/fixture.ts", | ||
| "declaration/VariableDeclaration/fixtures/_error_/const-id-type-no-init/fixture.ts", | ||
| "declaration/VariableDeclaration/fixtures/_error_/let-destructure-no-init/fixture.ts", | ||
| "declaration/VariableDeclaration/fixtures/_error_/let-destructure-type-no-init/fixture.ts", | ||
| "declaration/VariableDeclaration/fixtures/_error_/var-destructure-no-init/fixture.ts", | ||
| "declaration/VariableDeclaration/fixtures/_error_/var-destructure-type-no-init/fixture.ts", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
These are because we don't have the ability to detect whether a declaration is in an ambient context unless itself hasdeclare
| "declaration/VariableDeclaration/fixtures/_error_/const-id-definite-init/fixture.ts", | ||
| "declaration/VariableDeclaration/fixtures/_error_/const-id-definite-type-init/fixture.ts", | ||
| "declaration/VariableDeclaration/fixtures/_error_/declare-const-id-definite-init/fixture.ts", | ||
| "declaration/VariableDeclaration/fixtures/_error_/declare-const-id-definite-no-init/fixture.ts", | ||
| "declaration/VariableDeclaration/fixtures/_error_/declare-const-id-definite-type-no-init/fixture.ts", | ||
| "declaration/VariableDeclaration/fixtures/_error_/declare-let-id-definite-no-init/fixture.ts", | ||
| "declaration/VariableDeclaration/fixtures/_error_/declare-let-id-definite-type-no-init/fixture.ts", | ||
| "declaration/VariableDeclaration/fixtures/_error_/declare-var-id-definite-no-init/fixture.ts", | ||
| "declaration/VariableDeclaration/fixtures/_error_/declare-var-id-definite-type-no-init/fixture.ts", | ||
| "declaration/VariableDeclaration/fixtures/_error_/let-id-definite-init/fixture.ts", | ||
| "declaration/VariableDeclaration/fixtures/_error_/let-id-definite-no-init/fixture.ts", | ||
| "declaration/VariableDeclaration/fixtures/_error_/let-id-definite-type-init/fixture.ts", | ||
| "declaration/VariableDeclaration/fixtures/_error_/using-id-definite-init/fixture.ts", | ||
| "declaration/VariableDeclaration/fixtures/_error_/using-id-definite-type-init/fixture.ts", | ||
| "declaration/VariableDeclaration/fixtures/_error_/var-id-definite-init/fixture.ts", | ||
| "declaration/VariableDeclaration/fixtures/_error_/var-id-definite-no-init/fixture.ts", | ||
| "declaration/VariableDeclaration/fixtures/_error_/var-id-definite-type-init/fixture.ts", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Babel doesn't detect whether a definite assignment is put on a non-declared let/var with type and no init. This is arguably a Babel bug
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Nit: I wouldn't bother committing this - just leaving it as a note in the PR description should be enough for us to find it later if we want to reproduce this later.
JoshuaKGoldberg commentedJul 8, 2024
👋@Josh-Cena did you mean to re-request review on this? |
Josh-Cena commentedJul 12, 2024
I actually don't remember where the discussion left off. But yeah@bradzacher I think another look is worthwhile. I still want to keep the fixture generation script. |
bradzacher left a comment• edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I can't see one - could you please add an error fixture for
for(usingx!of[]){}
Other than that - looking fantastic!
We can land once you've got that!
bradzacher left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Can we also add this
interfaceVariableDeclarator{parent:VariableDeclaration;}
tohttps://github.com/typescript-eslint/typescript-eslint/blob/main/packages/types/src/ts-estree.ts for#6225
Josh-Cena commentedJul 14, 2024
Will come back to it next week...! |
Josh-Cena commentedJul 19, 2024
@bradzacher: unfortunately, |
codecovbot commentedJul 19, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@## main #9228 +/- ##==========================================+ Coverage 88.07% 88.27% +0.20%========================================== Files 402 422 +20 Lines 13693 14679 +986 Branches 3982 4299 +317 ==========================================+ Hits 12060 12958 +898- Misses 1324 1400 +76- Partials 309 321 +12
Flags with carried forward coverage won't be shown.Click here to find out more. |
bradzacher commentedJul 20, 2024
Yeah that's perfectly fine - if you have a look at the file you'll see that's the common pattern. Eventually we'll just want to add |
bradzacher commentedJul 20, 2024
bradzacher commentedJul 20, 2024
Most of the other ast changes have gone into v8 - do we want to also merge this into v8 as well to avoid the inevitable merge conflicts? |
Josh-Cena commentedJul 20, 2024
Mmmm, that's a good point, although other AST changes I sent have already gone into main. |
Josh-Cena commentedAug 11, 2024
Oof, I didn't realize this PR is still unmerged. I've resolved the conflicts. |


PR Checklist
Overview
I added A LOT of fixtures (programmatically of course) and I noticed that Babel didn't give some errors while IMO they should.