-
-
Notifications
You must be signed in to change notification settings - Fork 2.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 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): restrict variable declarator definite/init combinations #9228
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 on https://opencollective.com/typescript-eslint. |
✅ Deploy Preview for typescript-eslint ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
☁️ Nx Cloud ReportCI is running/has finished running commands for commit be1b324. 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 💌 from NxCloud. |
16faace
to
cea3f68
Compare
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.
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 has declare
"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
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.
👋 @Josh-Cena did you mean to re-request review on this? |
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. |
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 (using x! of []) {}
Other than that - looking fantastic!
We can land once you've got that!
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
interface VariableDeclarator {
parent: VariableDeclaration;
}
to https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/types/src/ts-estree.ts for #6225
Will come back to it next week...! |
@bradzacher: unfortunately, |
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. |
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 |
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? |
Mmmm, that's a good point, although other AST changes I sent have already gone into main. |
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.