Skip to content

Rule Change: no-promise-executor-return should allow arrow functions with no {...} #17278

Closed

Description

@nopeless

What rule do you want to change?

`no-promise-executor-return

What change to do you want to make?

Generate fewer warnings

How do you think the change should be implemented?

Change default behavior

Example code

// case 1
const sleep = (t) => new Promise(r => setTimeout(r, t))
const apiPromise = new Promise(r => apiRequestWithCallback("...", r));

// case 2
let getResolver;
// might be frowned upon
new Promise(r => j = r);

What does the rule currently do for this code?

does not allow this syntax because it is returning a value

What will the rule do after it's changed?

for case 1. require void in front of the arrow function

for case 2. ignore assignment returns

I believe these should be the default (not an option proposal)

Participation

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

Additional comments

No response

Activity

  1. added
    enhancementThis change enhances an existing feature of ESLint
    ruleRelates to ESLint's core rules
    on Jun 13, 2023
  2. moved this from Needs Triage to Triaging in Triageon Jun 13, 2023
  3. mdjermanovic commented on Jun 13, 2023

    @mdjermanovic
    Member

    Hi @nopeless, thanks for the issue!

    This was already discussed in #13668. I'd personally only support adding an option that allows => void <expression> and return void <expression>. Curios what other team members think about this.

  4. moved this from Triaging to Feedback Needed in Triageon Jun 13, 2023
  5. nopeless commented on Jun 13, 2023

    @nopeless
    ContributorAuthor

    Hi @nopeless, thanks for the issue!

    This was already discussed in #13668. I'd personally only support adding an option that allows => void <expression> and return void <expression>. Curios what other team members think about this.

    Oops, I did search for this rule proposal, I accidentally missed it, sorry

    I don't see how case 2 isn't in your favor though, I'd like to hear your thoughts

    Thanks for looking into the issue

  6. mdjermanovic commented on Jun 13, 2023

    @mdjermanovic
    Member

    I don't see how case 2 isn't in your favor though, I'd like to hear your thoughts

    I don't think this rule should be deciding which patterns look like intent to return a value and which don't. void as an indication that there is no intent to return a value seems fine to me.

  7. nzakas commented on Jun 13, 2023

    @nzakas
    Member

    This was already discussed in #13668. I'd personally only support adding an option that allows => void and return void . Curios what other team members think about this.

    I'm 👍 for this to cover case 1. It's a clear signal that you know you're not returning a value.

    I'm 👎 for covering case 2.

    @nopeless do you want to submit a pull request for that change?

  8. added
    acceptedThere is consensus among the team that this change meets the criteria for inclusion
    on Jun 13, 2023
  9. moved this from Feedback Needed to Ready to Implement in Triageon Jun 13, 2023
  10. nopeless commented on Jun 13, 2023

    @nopeless
    ContributorAuthor

    I don't see how case 2 isn't in your favor though, I'd like to hear your thoughts

    I don't think this rule should be deciding which patterns look like intent to return a value and which don't. void as an indication that there is no intent to return a value seems fine to me.

    Maybe my thinking is wrong, but I don't think there exists a developer smart enough to know that the assignment operator in js also returns the LHS value but ignorant enough to think that the function's return value has some sort of meaning.

    I did see some new developers struggling to debug their code because they used if (a = b). I personally use let result; if (result = someFunction()) {} pattern a lot. (this is prevented by no-cond-assign)

    However, I don't mind putting {} around assignments. Its a rather rare case to do so

  11. nopeless commented on Jun 13, 2023

    @nopeless
    ContributorAuthor

    This was already discussed in #13668. I'd personally only support adding an option that allows => void and return void . Curios what other team members think about this.

    I'm 👍 for this to cover case 1. It's a clear signal that you know you're not returning a value.

    I'm 👎 for covering case 2.

    @nopeless do you want to submit a pull request for that change?

    I'd sure love to try, I'll look at the contributing guide

  12. nopeless commented on Jun 14, 2023

    @nopeless
    ContributorAuthor

    Meanwhile, this seems like a similar issue to array-callback-return rule. Should I submit a different issue for that?

  13. nopeless commented on Jun 14, 2023

    @nopeless
    ContributorAuthor

    @mdjermanovic I'd like your opinion on this

  14. mdjermanovic commented on Jun 14, 2023

    @mdjermanovic
    Member

    @mdjermanovic I'd like your opinion on this

    On allowing .forEach(() => void...) in array-callback-return? Yes, that seems similar and we can discuss it, and yes it would be better to submit a separate issue.

  15. moved this from Ready to Implement to Complete in Triageon Aug 20, 2023
  16. locked and limited conversation to collaborators on Feb 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    acceptedThere is consensus among the team that this change meets the criteria for inclusionarchived due to ageThis issue has been archived; please open a new issue for any further discussionenhancementThis change enhances an existing feature of ESLintruleRelates to ESLint's core rules

    Type

    No type

    Projects

    • Status
      Complete

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions