-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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-duplicate-type-constituents] shouldn't report on error types #9600
fix(eslint-plugin): [no-duplicate-type-constituents] shouldn't report on error types #9600
Conversation
Thanks for the PR, @y-hsgw! 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 e26563d. 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. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #9600 +/- ##
=======================================
Coverage 88.45% 88.45%
=======================================
Files 422 422
Lines 14695 14697 +2
Branches 4298 4299 +1
=======================================
+ Hits 12998 13000 +2
Misses 1372 1372
Partials 325 325
Flags with carried forward coverage won't be shown. Click here to find out more.
|
if ( | ||
actualNodeKeys.some( | ||
actualNodeKey => | ||
!isSameAstNode( | ||
actualNode[actualNodeKey as keyof typeof actualNode], | ||
expectedNode[actualNodeKey as keyof typeof expectedNode], | ||
), | ||
) | ||
) { | ||
return false; | ||
} | ||
return true; | ||
return !actualNodeKeys.some( | ||
actualNodeKey => | ||
!isSameAstNode( | ||
actualNode[actualNodeKey as keyof typeof actualNode], | ||
expectedNode[actualNodeKey as keyof typeof expectedNode], | ||
), | ||
); |
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 changes don't seem to be related to the issue this PR solves?
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 thought it was minor, so I went ahead and fixed it.
However, as you mentioned, it's unrelated to this PR, so I reverted it.
1560c83
const constituentNodeType = checker.getTypeAtLocation( | ||
parserServices.esTreeNodeToTSNodeMap.get(constituentNode), | ||
); |
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.
const constituentNodeType = checker.getTypeAtLocation( | |
parserServices.esTreeNodeToTSNodeMap.get(constituentNode), | |
); | |
const constituentNodeType = parserServices.getTypeAtLocation(constituentNode); |
ParserServices
has a nice utility function to do this :)
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.
Nice! Thank you :) Fixed in fc5d5d8.
if (tsutils.isIntrinsicErrorType(constituentNodeType)) { | ||
return []; | ||
} |
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.
if (tsutils.isIntrinsicErrorType(constituentNodeType)) { | |
return []; | |
} | |
if (tsutils.isIntrinsicErrorType(constituentNodeType)) { | |
return uniqueConstituents; | |
} |
As I understand this logic, uniqueConstituents
is a kind of cache for finding duplicates using only AST (since it's faster than calling a checker to make type-level comparisons). See this comment #5728 (comment)
If we return an empty array, we discard all previously found unique constituents and fallback to type-level checks, this may result in some performance penalty.
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.
Thank you for the guidance. Fixed in 6683e36.
{ | ||
code: 'type T = Class<string> | Class<string>;', | ||
output: `type T = Class<string> ;`, | ||
errors: [ | ||
{ | ||
messageId: 'duplicate', | ||
data: { | ||
type: 'Union', | ||
previous: 'Class<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.
[Testing] If this case is no longer reported as an error, let's just move it to the valid
section instead of deleting it?
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.
Indeed, that's correct. I moved the tests in 3cf71ad.
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.
[Testing] It would be great if we had some test cases (both valid and invalid) that mix error types with normal types
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 added the tests in 3cf71ad.
…to fix/no-duplicate-type-constituents
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.
🔥
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.
Woop, thanks!
3591b78
into
typescript-eslint:main
PR Checklist
Overview