Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
fix(eslint-plugin): [no-unnecessary-type-constraint] correctly fix in cts/mts files#6795
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
fix(eslint-plugin): [no-unnecessary-type-constraint] correctly fix in cts/mts files#6795
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Thanks for the PR,@WoodyWoodsta! 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. |
WoodyWoodsta commentedMar 30, 2023
I've specifically left out unit tests for this, as it doesn't appear that any of the fixtures for |
nx-cloudbot commentedMar 30, 2023 • 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.
WoodyWoodsta commentedMar 30, 2023
I've noticed two things:
|
netlifybot commentedMar 30, 2023 • 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. |
Uh oh!
There was an error while loading.Please reload this page.
WoodyWoodsta commentedMar 30, 2023
@bradzacher I'm trying to understand why the proposition you made which was simply to use the Regardless, there was no logic in the rule which checked for jsx/js, only the fix method. So I've added a new util to serve as a bypass for this rule. I have no idea if this is the correct approach: to me it doesn't seem elegant. |
packages/eslint-plugin/src/rules/no-unnecessary-type-constraint.ts OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
codecovbot commentedMar 30, 2023 • 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 Report
Additional details and impacted files@@ Coverage Diff @@## main #6795 +/- ##======================================= Coverage 87.47% 87.47% ======================================= Files 379 379 Lines 13228 13234 +6 Branches 3905 3906 +1 =======================================+ Hits 11571 11577 +6 Misses 1279 1279 Partials 378 378
Flags with carried forward coverage won't be shown.Click here to find out more.
|
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.
Apologies - it appears that I've lead you astray due to my misunderstanding of TS.
I've never actually used.mts for JSX, but I knew it errored on JSX-ambiguous syntax, so I had assumed it actually supported JSX.
In testing I now see that this isn't actually the case -.mts/.cts doesn't support JSX, it just errors on ambiguous syntax, and does not actually support JSX in the files. I assume that this just the TS team future-proofing - reading the design meeting notes it appears like they didn't want to lock in one-way or the other for the first release, so they just made sure they could make it JSX later if they wanted to by banning ambiguous syntax.
This obviously the reason why thegetScriptKind function returns "TS" as the kind for the file instead of "TSX" - which was another thing I hadn't noticed in passing earlier.
Which provides a problem as you've noticed our suggested solution obviously won't fix it.
So what would be a good solution?
Now that I know what we know - I think we should just go back to hard-coding this. Something like this would do the job:
functionrequiresGenericDeclarationDisambiguation(filename:string){constext=path.ext(filename).toLowerCase();switch(ext){casets.Extension.Tsx:casets.Extension.Cts:casets.Extension.Mts:returntrue;default:returnfalse;}}
Uh oh!
There was an error while loading.Please reload this page.
packages/eslint-plugin/src/rules/no-unnecessary-type-constraint.ts OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
WoodyWoodsta commentedApr 2, 2023 • 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.
@bradzacher To sum up your comments and relate to the issue: Original Issue
Fix
No changes to eslint fix required. Let me know if this sounds correct. Of course this could also be resolved in some way in formatters (i.e. to not strip the dangling comma here), but:
|
bradzacher commentedApr 2, 2023 • 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.
If prettier is stripping the syntactically necessary comma when formatting a It has already been reported:prettier/prettier#14518
Formatters are powered by the AST - they know exactly and unambiguously that The formatter then decides how to print the code from the AST - if it decides to prints the type parameter on a single line, its trivial to also insert the comma. |
bradzacher commentedApr 2, 2023 • 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.
This is not correct, no. The rule shouldalways report on the unnecessary The current rule behaviour is toalways report - but the erroneous behaviour is that it removes it in |
WoodyWoodsta commentedApr 3, 2023
@bradzacher Ok you confirm what I thought. So if I understand correctly, there is actually nothing to do here in |
bradzacher commentedApr 3, 2023
Mylast comment describes the change we need to make to the rule - we need to fix to |
WoodyWoodsta commentedApr 3, 2023
@bradzacher Hopefully I've now understood. Please see6bfccc6 |
WoodyWoodsta commentedApr 20, 2023
@bradzacher Any thoughts on the above? |
packages/eslint-plugin/src/rules/no-unnecessary-type-constraint.ts OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
JoshuaKGoldberg commentedJul 16, 2023
@bradzacher is this still something you have time to review? |
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.
this LGTM!
Uh oh!
There was an error while loading.Please reload this page.
PR Checklist
Overview
.mts,ctsas well as jsx variant files