-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
fix(eslint-plugin): [array-type] --fix flag removes parentheses from type #5997
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
fix(eslint-plugin): [array-type] --fix flag removes parentheses from type #5997
Conversation
Array type with intersection that has parentheses does not retain the parens. typescript-eslint#5941
Thanks for the PR, @mhnaeem! 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 settings. |
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #5997 +/- ##
=======================================
Coverage 91.42% 91.42%
=======================================
Files 365 365
Lines 12339 12339
Branches 3609 3608 -1
=======================================
Hits 11281 11281
Misses 753 753
Partials 305 305
Flags with carried forward coverage won't be shown. Click here to find out more.
|
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.
Interesting—the fixer looks a bit hacky to me overall, but if there are no regressions, I like how simple the fix is.
testOutput( | ||
'array', | ||
` | ||
type WorkingArray = { | ||
outerProperty: Array< | ||
{ innerPropertyOne: string } & { innerPropertyTwo: string } | ||
>; | ||
} | ||
|
||
type BrokenArray = { | ||
outerProperty: Array< | ||
({ innerPropertyOne: string } & { innerPropertyTwo: string }) | ||
>; | ||
} | ||
`, | ||
` | ||
type WorkingArray = { | ||
outerProperty: ({ innerPropertyOne: string } & { innerPropertyTwo: string })[]; | ||
} | ||
|
||
type BrokenArray = { | ||
outerProperty: ({ innerPropertyOne: string } & { innerPropertyTwo: string })[]; | ||
} | ||
`, | ||
); |
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 test case looks identical to the one above?
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.
@Josh-Cena One is with type and the other one is with interface, I wanted to be sure it doesn't affect the code different on either keyword. I can modify it a bit if you like @Josh-Cena
Maybe something like
type BrokenArray = Array<({ a: number } & { b: string })>
@Josh-Cena I could not think of any regressions and the tests passed as well, if you have any other test cases you would like me to include I will be happy to. |
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.
Thanks, it seems to work 👍
For the record, the code was changed in #3340 |
PR Checklist
--fix
removes neccesary brackets leading to a type with a different meaning #5941Overview
Array type with intersection that has parentheses does not retain the parens. Remove an unnecessary check since the type node doesn't include parens.