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): [no-redundant-type-constituents] incorrectly marks & string as redundant #8282
Conversation
…ks & string as redundant fixes: typescript-eslint#7580
Thanks for the PR, @arka1002! 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. |
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! This rule is trickier than I remembered it being 😅 nice job adding to its logic. Thanks for sending this!
I think I understand what the new code is doing, but it was a little hard to read through. A couple general suggestions:
- Try to stick with the existing conventions in code unless there's a strong reason to deviate
- Try to use informative names when possible, not general ones like
key
oriterator
The core logic seems reasonable to me. Requesting changes on refactors. There might be a point where more tests would be reasonable depending on one or two of them?
packages/eslint-plugin/src/rules/no-redundant-type-constituents.ts
Outdated
Show resolved
Hide resolved
packages/eslint-plugin/src/rules/no-redundant-type-constituents.ts
Outdated
Show resolved
Hide resolved
packages/eslint-plugin/src/rules/no-redundant-type-constituents.ts
Outdated
Show resolved
Hide resolved
packages/eslint-plugin/src/rules/no-redundant-type-constituents.ts
Outdated
Show resolved
Hide resolved
packages/eslint-plugin/src/rules/no-redundant-type-constituents.ts
Outdated
Show resolved
Hide resolved
value.forEach(union => { | ||
typeFlagsOfUnions.push(union.typeFlags); | ||
}); |
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.
[Style] Is there a need to have a shared variable outside the forEach
? Switching it to being inside the .forEach
and never modified doesn't fail any unit tests:
value.forEach(union => { | |
typeFlagsOfUnions.push(union.typeFlags); | |
}); | |
const typeFlagsOfUnions = unionTypeFlags.flatMap( | |
union => | |
union.typeFlags as keyof typeof literalToPrimitiveTypeFlags, | |
); |
That includes an extra tip: since we know the type flags are all the keyof typeof literalToPrimitiveTypeFlags
, using the assertion early on means we don't need multiple assertions 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.
I removed the variable, I dont think we need it anymore.
I might need some help with the type assertions though 😅
packages/eslint-plugin/src/rules/no-redundant-type-constituents.ts
Outdated
Show resolved
Hide resolved
packages/eslint-plugin/src/rules/no-redundant-type-constituents.ts
Outdated
Show resolved
Hide resolved
packages/eslint-plugin/src/rules/no-redundant-type-constituents.ts
Outdated
Show resolved
Hide resolved
Co-authored-by: Josh Goldberg ✨ <git@joshuakgoldberg.com>
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #8282 +/- ##
==========================================
- Coverage 87.84% 87.07% -0.77%
==========================================
Files 397 251 -146
Lines 13844 12285 -1559
Branches 4073 3871 -202
==========================================
- Hits 12161 10697 -1464
+ Misses 1381 1316 -65
+ Partials 302 272 -30
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.
fixes: #7580
PR Checklist
no-redundant-type-constituents
incorrectly marks& string
as redundant #7580Overview