Skip to content

feat(eslint-plugin): [no-confusing-void-expression] add an option to ignore void<->void #10067

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
merged 28 commits into from
Nov 4, 2024

Conversation

ronami
Copy link
Member

@ronami ronami commented Sep 27, 2024

PR Checklist

Overview

This PR addresses #8538 and adds an option (namely ignoreVoidReturningFunctions) that allows returning void expressions from either:

  • Functions explicitly annotated with void as one of their return types.
  • Their contextual type includes void.

I enabled the rule back on @typescript-eslint's monorepo (since it's currently disabled) with the option and had to fix one error that looks valid. Running the rule on @typescript-eslint's monorepo helped me figure out the various edge cases of the rule (hopefully, I didn't miss a whole lot).

I added a "game plan" comment after seeing @kirkwaiblinger do this on several other rules, and it has been helpful to read through.

One open question I have is whether or not this should apply to async functions. I mean, if the following should be valid or not:

function returnsVoid(): void {}

async function foo(): Promise<void> {
  return returnsVoid();
}

Please let me know if this makes sense or if I missed anything.

Edit: Only when I finished most of the work I noticed the linked PR of #8632. I noticed I was missing a bunch of tests and added the ones I was missing, thanks @developer-bandi 🙏

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @ronami!

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 Sep 27, 2024

Deploy Preview for typescript-eslint ready!

Name Link
🔨 Latest commit 8b85c14
🔍 Latest deploy log https://app.netlify.com/sites/typescript-eslint/deploys/670a15a2d4fac700082ea430
😎 Deploy Preview https://deploy-preview-10067--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: 94 (no change 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 Sep 27, 2024

☁️ Nx Cloud Report

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

@ronami ronami changed the title [no-confusing-void-expression] Add option to ignore void<->void feat(eslint-plugin): [no-confusing-void-expression] Add option to ignore void<->void Sep 27, 2024
@ronami ronami changed the title feat(eslint-plugin): [no-confusing-void-expression] Add option to ignore void<->void feat(eslint-plugin): [no-confusing-void-expression] Add an option to ignore void<->void Sep 27, 2024
@ronami ronami changed the title feat(eslint-plugin): [no-confusing-void-expression] Add an option to ignore void<->void feat(eslint-plugin): Add an option to ignore void<->void on [no-confusing-void-expression] Sep 27, 2024
@ronami ronami changed the title feat(eslint-plugin): Add an option to ignore void<->void on [no-confusing-void-expression] feat(eslint-plugin): add an option to ignore void<->void on [no-confusing-void-expression] Sep 27, 2024
@ronami ronami changed the title feat(eslint-plugin): add an option to ignore void<->void on [no-confusing-void-expression] feat(eslint-plugin): [no-confusing-void-expression] add an option to ignore void<->void Sep 27, 2024
Copy link

codecov bot commented Sep 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 86.12%. Comparing base (974d9ce) to head (8b85c14).
Report is 80 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #10067      +/-   ##
==========================================
+ Coverage   86.09%   86.12%   +0.02%     
==========================================
  Files         428      429       +1     
  Lines       14969    14995      +26     
  Branches     4343     4351       +8     
==========================================
+ Hits        12888    12914      +26     
  Misses       1734     1734              
  Partials      347      347              
Flag Coverage Δ
unittest 86.12% <100.00%> (+0.02%) ⬆️

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

Files with missing lines Coverage Δ
...t-plugin/src/rules/no-confusing-void-expression.ts 100.00% <100.00%> (ø)
...ckages/eslint-plugin/src/rules/no-unsafe-return.ts 97.22% <100.00%> (-0.22%) ⬇️
...es/eslint-plugin/src/util/getParentFunctionNode.ts 100.00% <100.00%> (ø)

@ronami ronami marked this pull request as ready for review September 27, 2024 18:54
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.

Looks like a great start to me! Mostly requesting changes on docs & testing, the game plan seems very reasonable. 🏈

Copy link
Member

Choose a reason for hiding this comment

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

[Praise] I like the reuse here 🙂 nice.

Comment on lines 454 to 457
if (
ts.isFunctionExpression(functionTSNode) ||
ts.isArrowFunction(functionTSNode)
) {
Copy link
Member

Choose a reason for hiding this comment

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

[Style] Nit: a little less code to read & run here, as getContextualType is just looking for expressions:

Suggested change
if (
ts.isFunctionExpression(functionTSNode) ||
ts.isArrowFunction(functionTSNode)
) {
if (ts.isExpression(functionTSNode)) {

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice.

Copy link
Member Author

@ronami ronami Oct 11, 2024

Choose a reason for hiding this comment

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

I've seen this done here. Would it make sense to send a tiny PR to shorten it in a similar way? Looks like it works out locally.

Copy link
Member

Choose a reason for hiding this comment

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

If you want, I'd 👍 it!

@JoshuaKGoldberg JoshuaKGoldberg added the awaiting response Issues waiting for a reply from the OP or another party label Oct 10, 2024
@JoshuaKGoldberg
Copy link
Member

@ronami is this ready for re-review?

We normally wait to be explicitly re-requested, so we're holding off posting more comments for now.

@ronami
Copy link
Member Author

ronami commented Oct 21, 2024

@ronami is this ready for re-review?

We normally wait to be explicitly re-requested, so we're holding off posting more comments for now.

Oh, I wasn't aware of this. Yes! It is ready for review.

@JoshuaKGoldberg
Copy link
Member

Great thanks!

In the future, you can use the actual GitHub feature: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/about-pull-request-reviews#re-requesting-a-review. That'll put it back on our queue. We have automations around it to remove the awaiting response label.

@github-actions github-actions bot removed the awaiting response Issues waiting for a reply from the OP or another party label Oct 22, 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.

Looks great, thanks for all the changes!

Renee Young hand-waving saying "Glorious!"

@JoshuaKGoldberg JoshuaKGoldberg merged commit e2e9ffc into typescript-eslint:main Nov 4, 2024
63 checks passed
@ronami ronami deleted the ignore-void-void branch November 4, 2024 17:31
renovate bot added a commit to mmkal/eslint-plugin-mmkal that referenced this pull request Nov 11, 2024
##### [v8.14.0](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#8140-2024-11-11)

##### 🚀 Features

-   **eslint-plugin:** \[await-thenable] report unnecessary `await using` statements ([#10209](typescript-eslint/typescript-eslint#10209))
-   **eslint-plugin:** \[no-confusing-void-expression] add an option to ignore void<->void ([#10067](typescript-eslint/typescript-eslint#10067))

##### 🩹 Fixes

-   **scope-manager:** fix asserted increments not being marked as write references ([#10271](typescript-eslint/typescript-eslint#10271))
-   **eslint-plugin:** \[no-misused-promises] improve report loc for methods ([#10216](typescript-eslint/typescript-eslint#10216))
-   **eslint-plugin:** \[no-unnecessary-condition] improve error message for literal comparisons ([#10194](typescript-eslint/typescript-eslint#10194))

##### ❤️  Thank You

-   Gyumong [@gyumong](https://github.com/Gyumong)
-   Jan Ochwat [@janek515](https://github.com/janek515)
-   Kirk Waiblinger [@kirkwaiblinger](https://github.com/kirkwaiblinger)
-   Ronen Amiel

You can read about our [versioning strategy](https://main--typescript-eslint.netlify.app/users/versioning) and [releases](https://main--typescript-eslint.netlify.app/users/releases) on our website.
renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request Nov 12, 2024
| datasource | package                          | from   | to     |
| ---------- | -------------------------------- | ------ | ------ |
| npm        | @typescript-eslint/eslint-plugin | 8.13.0 | 8.14.0 |
| npm        | @typescript-eslint/parser        | 8.13.0 | 8.14.0 |


## [v8.14.0](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#8140-2024-11-11)

##### 🚀 Features

-   **eslint-plugin:** \[await-thenable] report unnecessary `await using` statements ([#10209](typescript-eslint/typescript-eslint#10209))
-   **eslint-plugin:** \[no-confusing-void-expression] add an option to ignore void<->void ([#10067](typescript-eslint/typescript-eslint#10067))

##### 🩹 Fixes

-   **scope-manager:** fix asserted increments not being marked as write references ([#10271](typescript-eslint/typescript-eslint#10271))
-   **eslint-plugin:** \[no-misused-promises] improve report loc for methods ([#10216](typescript-eslint/typescript-eslint#10216))
-   **eslint-plugin:** \[no-unnecessary-condition] improve error message for literal comparisons ([#10194](typescript-eslint/typescript-eslint#10194))

##### ❤️  Thank You

-   Gyumong [@gyumong](https://github.com/Gyumong)
-   Jan Ochwat [@janek515](https://github.com/janek515)
-   Kirk Waiblinger [@kirkwaiblinger](https://github.com/kirkwaiblinger)
-   Ronen Amiel

You can read about our [versioning strategy](https://main--typescript-eslint.netlify.app/users/versioning) and [releases](https://main--typescript-eslint.netlify.app/users/releases) on our website.
renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request Nov 12, 2024
| datasource | package                          | from   | to     |
| ---------- | -------------------------------- | ------ | ------ |
| npm        | @typescript-eslint/eslint-plugin | 8.13.0 | 8.14.0 |
| npm        | @typescript-eslint/parser        | 8.13.0 | 8.14.0 |


## [v8.14.0](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#8140-2024-11-11)

##### 🚀 Features

-   **eslint-plugin:** \[await-thenable] report unnecessary `await using` statements ([#10209](typescript-eslint/typescript-eslint#10209))
-   **eslint-plugin:** \[no-confusing-void-expression] add an option to ignore void<->void ([#10067](typescript-eslint/typescript-eslint#10067))

##### 🩹 Fixes

-   **scope-manager:** fix asserted increments not being marked as write references ([#10271](typescript-eslint/typescript-eslint#10271))
-   **eslint-plugin:** \[no-misused-promises] improve report loc for methods ([#10216](typescript-eslint/typescript-eslint#10216))
-   **eslint-plugin:** \[no-unnecessary-condition] improve error message for literal comparisons ([#10194](typescript-eslint/typescript-eslint#10194))

##### ❤️  Thank You

-   Gyumong [@gyumong](https://github.com/Gyumong)
-   Jan Ochwat [@janek515](https://github.com/janek515)
-   Kirk Waiblinger [@kirkwaiblinger](https://github.com/kirkwaiblinger)
-   Ronen Amiel

You can read about our [versioning strategy](https://main--typescript-eslint.netlify.app/users/versioning) and [releases](https://main--typescript-eslint.netlify.app/users/releases) on our website.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enhancement: [no-confusing-void-expression] Add option to ignore void<->void
2 participants