Skip to content

fix(utils): add TSDeclareFunction to functionTypeTypes #9788

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

Merged

Conversation

abrahamguo
Copy link
Contributor

@abrahamguo abrahamguo commented Aug 13, 2024

PR Checklist

Overview

From b47b88f, TSDeclareFunction was missing from functionTypeTypes.

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @abrahamguo!

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 Aug 13, 2024

Deploy Preview for typescript-eslint ready!

Name Link
🔨 Latest commit 5a425ff
🔍 Latest deploy log https://app.netlify.com/sites/typescript-eslint/deploys/66bc0f23758a9500075674c3
😎 Deploy Preview https://deploy-preview-9788--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: 98 (🔴 down 2 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.

Copy link

nx-cloud bot commented Aug 13, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 5a425ff. 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.

@abrahamguo abrahamguo changed the title bug(utils): add TSDeclareFunction to functionTypeTypes fix(utils): add TSDeclareFunction to functionTypeTypes Aug 13, 2024
@kirkwaiblinger
Copy link
Member

Would you mind filing an issue for this and/or fleshing out the description with the PR that this change is fixing up? The commit referenced says it's not on a branch within this repo, so it's hard to figure out what this is in reference to

@kirkwaiblinger kirkwaiblinger added awaiting response Issues waiting for a reply from the OP or another party please fill out the template we have the processes for good reasons 😔 labels Aug 13, 2024
@abrahamguo
Copy link
Contributor Author

Yep, sorry! This came from #9479.

I agree with @auvred, I will add some unit tests to validate this change.

@abrahamguo abrahamguo requested a review from auvred August 14, 2024 01:58
@github-actions github-actions bot removed the awaiting response Issues waiting for a reply from the OP or another party label Aug 14, 2024
@abrahamguo
Copy link
Contributor Author

In no-redundant-type-constituents, never is not allowed in unions.
However, an exception is for function return types, where it is allowed in unions.
Because TSDeclareFunction was missing from functionTypeTypes, the rule wrongly did report for TSDeclareFunctions but not other function types, as shown in @auvred's example:

declare function fn(): never | 'foo' // wrongly reports
type ffn = () => never | 'foo'

In this PR, it now correctly recognizes TSDeclareFunction as a function type, and now no longer reports.

@@ -171,7 +170,7 @@ function describeLiteralTypeNode(typeNode: TSESTree.TypeNode): string {
function isNodeInsideReturnType(node: TSESTree.TSUnionType): boolean {
return !!(
node.parent.type === AST_NODE_TYPES.TSTypeAnnotation &&
(isFunctionType(node.parent.parent) || isFunction(node.parent.parent))
isFunctionOrFunctionType(node.parent.parent)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

isFunctionOrFunctionType simply combines the checks of the two functions into one

@auvred auvred added 1 approval >=1 team member has approved this PR; we're now leaving it open for more reviews before we merge and removed please fill out the template we have the processes for good reasons 😔 labels Aug 24, 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.

LGTM, thanks for the cleanup! 🙌

@JoshuaKGoldberg JoshuaKGoldberg merged commit 6377f18 into typescript-eslint:main Aug 24, 2024
66 of 67 checks passed
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 1, 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.

4 participants