Skip to content
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

Conversation

y-hsgw
Copy link
Contributor

@y-hsgw y-hsgw commented Jul 20, 2024

PR Checklist

Overview

  • Fixed to not report errors.
  • Minor refactor.

@typescript-eslint
Copy link
Contributor

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.

Copy link

netlify bot commented Jul 20, 2024

Deploy Preview for typescript-eslint ready!

Name Link
🔨 Latest commit e26563d
🔍 Latest deploy log https://app.netlify.com/sites/typescript-eslint/deploys/66a729ae6ce4ab00092fcf29
😎 Deploy Preview https://deploy-preview-9600--typescript-eslint.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 100 (🟢 up 1 from production)
Accessibility: 100 (no change from production)
Best Practices: 92 (no change from production)
SEO: 90 (no change from production)
PWA: 80 (no change from production)
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify site configuration.

@y-hsgw y-hsgw changed the title fix(eslint-plugin): [no-duplicate-type-constituents] Shouldn't report on error types fix(eslint-plugin): [no-duplicate-type-constituents] shouldn't report on error types Jul 20, 2024
Copy link

nx-cloud bot commented Jul 20, 2024

☁️ Nx Cloud Report

CI 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 targets

Sent with 💌 from NxCloud.

Copy link

codecov bot commented Jul 20, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.45%. Comparing base (6b92aa5) to head (e26563d).

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           
Flag Coverage Δ
unittest 88.45% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
...plugin/src/rules/no-duplicate-type-constituents.ts 100.00% <100.00%> (ø)

Comment on lines 53 to 60
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],
),
);
Copy link
Member

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?

Copy link
Contributor Author

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

Comment on lines 110 to 112
const constituentNodeType = checker.getTypeAtLocation(
parserServices.esTreeNodeToTSNodeMap.get(constituentNode),
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const constituentNodeType = checker.getTypeAtLocation(
parserServices.esTreeNodeToTSNodeMap.get(constituentNode),
);
const constituentNodeType = parserServices.getTypeAtLocation(constituentNode);

ParserServices has a nice utility function to do this :)

Copy link
Contributor Author

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.

Comment on lines 113 to 115
if (tsutils.isIntrinsicErrorType(constituentNodeType)) {
return [];
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Copy link
Contributor Author

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.

Comment on lines -278 to -290
{
code: 'type T = Class<string> | Class<string>;',
output: `type T = Class<string> ;`,
errors: [
{
messageId: 'duplicate',
data: {
type: 'Union',
previous: 'Class<string>',
},
},
],
},
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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

Copy link
Contributor Author

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.

@auvred auvred added the awaiting response Issues waiting for a reply from the OP or another party label Jul 28, 2024
@y-hsgw y-hsgw requested a review from auvred July 29, 2024 05:47
@github-actions github-actions bot removed the awaiting response Issues waiting for a reply from the OP or another party label Jul 29, 2024
Copy link
Member

@auvred auvred left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥

@auvred auvred added the 1 approval >=1 team member has approved this PR; we're now leaving it open for more reviews before we merge label Jul 29, 2024
Copy link
Member

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woop, thanks!

@JoshuaKGoldberg JoshuaKGoldberg merged commit 3591b78 into typescript-eslint:main Jul 29, 2024
62 of 63 checks passed
@y-hsgw y-hsgw deleted the fix/no-duplicate-type-constituents branch July 29, 2024 16:34
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
1 approval >=1 team member has approved this PR; we're now leaving it open for more reviews before we merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: [no-duplicate-type-constituents] Shouldn't report on error types
3 participants