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

Rule Change: allow void in array-callback-return for Array.prototype.forEach #17285

Closed
1 task done
nopeless opened this issue Jun 14, 2023 · 12 comments
Closed
1 task done
Assignees
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules

Comments

@nopeless
Copy link
Contributor

What rule do you want to change?

array-callback-return

What change to do you want to make?

Implement suggestions

How do you think the change should be implemented?

A new option

Example code

// example of a non-void side-effect function
[1,2,3].forEach(n => cls.computeCache(n))

// will suggest the following
// Insert void
[1,2,3].forEach(n => void cls.computeCache(n))
// Wrap in {}
[1,2,3].forEach(n => {cls.computeCache(n)})

What does the rule currently do for this code?

Rightfully marks it as wrong, as return value of forEach's callback is ignored

However, even adding a void in front does not fix the issue, and there are no IDE suggestions

What will the rule do after it's changed?

add a new option allowVoid. It will share the same logic that I have implemented for detecting void and suggesting fixes in #17282

If #17282 passes, then it is logical that this rule has consistent options and behavior.

Participation

  • I am willing to submit a pull request to implement this change.

Additional comments

I think I saw an issue related to forEach and void, but I can't seem to find it for now

@nopeless nopeless added enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules labels Jun 14, 2023
@sam3k
Copy link
Contributor

sam3k commented Jun 15, 2023

Hey @nopeless, I am not too familiar with this lint rule and I'm trying to repro in the playground but do not see it marking any of the examples you've provided as wrong. Am I missing something? Could you update the playground example?

@nopeless
Copy link
Contributor Author

repro

@sam3k

Sorry, forgot to mention that this only happens when check foreach is enabled

@mdjermanovic
Copy link
Member

Makes sense to me 👍

@nzakas
Copy link
Member

nzakas commented Jul 10, 2023

I am also in favor. @nopeless do you want to submit a PR for this?

@nzakas nzakas added the accepted There is consensus among the team that this change meets the criteria for inclusion label Jul 10, 2023
@nopeless
Copy link
Contributor Author

Would you mind if i do this on the same PR thats currently open right now @nzakas

@nzakas
Copy link
Member

nzakas commented Jul 11, 2023

@nopeless we need it on a separate pull request so we can evaluate each separately.

@sam3k
Copy link
Contributor

sam3k commented Jul 19, 2023

@nopeless will you be able to create a separate PR?

@nopeless
Copy link
Contributor Author

nopeless commented Jul 19, 2023

@nopeless will you be able to create a separate PR?

Yes, but I am planning to do it after #17282 is merged since it would be easier that way

@snitin315 snitin315 self-assigned this Sep 3, 2023
@Tanujkanti4441
Copy link
Contributor

@snitin315 are you working on this currently?

@snitin315
Copy link
Contributor

@Tanujkanti4441 feel free to work on this.

mdjermanovic pushed a commit that referenced this issue Sep 17, 2023
* feat: allowVoid option in array-callback-return

Refs #17285

* feat: refactor code and add docs

* feat: allow void in return-statement

* feat: add more tests for allowVoid
@mdjermanovic
Copy link
Member

PR #17564 that implements the new option allowVoid has been merged. The remaining task is to implement suggestions.

@mdjermanovic
Copy link
Member

Fixed by #17564 and #17590.

@eslint-github-bot eslint-github-bot bot locked and limited conversation to collaborators Mar 21, 2024
@eslint-github-bot eslint-github-bot bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Mar 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules
Projects
Archived in project
Development

No branches or pull requests

6 participants