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
Create except-object
exception to arrow-body-style
rule, enforcing explicit return of object literals from arrow functions.
#5936
Comments
…t#5936) Blockless arrow functions are awesome, but when returning an object literal it's necessary to enclose the return value in parentheses. This rule extension enforces blockless arrow functions excluding cases where the arrow function returns an object literal.
I'm not sure I'm understanding this correctly. You're proposing to add an option that requires the use of |
Yes, exactly. |
I think this is a fair request. |
…t#5936) Blockless arrow functions are awesome, but when returning an object literal it's necessary to enclose the return value in parentheses. This rule extension enforces blockless arrow functions excluding cases where the arrow function returns an object literal.
@BYK are you championing this change? My feedback:
|
Yes, the naming for this is a little awkward. "except-object" is a refinement of "as-needed", not a distinct third option. Conceivably, this could live as its own eslint plugin ( |
Don't want to over commit so holding on for championing for now in case someone else can do it. If we can't find anyone else in a week I'll take it on. Sounds good? Also agree that this needs more discussion and consideration before moving forward with the code. |
@eslint/eslint-team - anyone else interested in this rule? Either championing or contributing to the discussion? |
I vote that this should be a third option as its not truly needed. |
@BYK it's been a week, are you championing? :) Also, agree with @mikesherov that this would be a third option. |
@nzakas - okay you got me, championing. |
Okay, we just need three 👍s to move forward. I'll give you one: 👍 |
👍 |
👍 @BYK I could also take this |
@alberto I'm just getting back to speed so if you have free time go for it. Otherwise I'll get to this eventually :) |
Cool |
I added the |
I'm having trouble finding a name for a standalone option :( Any ideas? |
What do you think of a third argument which refines the existing "as-needed" setting? "arrow-body-style": [2, "as-needed", "skip-object-literal"] |
We could do @BYK as champion, can you drive this discussion to a conclusion? |
What do you think of using an extension similar to the "arrow-body-style": [2, "as-needed", { avoidParens: true }] |
I don't think |
I'm +1 to |
Added "needs bikeshedding" label since we're still hashing a few things out. |
I think this should be an option for |
Thanks, that makes more sense to me. I was bit confused by the previous conversation. Should we use |
@alberto - I'm not really sure actually. What do you think? |
Ok, I think I see your point. |
I'd close #5934 since it was created before the issue was accepted (hence before all these discussions). That said since @duncanbeevers is a new collaborator, there's a case to get his first patch in too. What do you think @ilyavolodin and @alberto. |
I think we should favor new contributions here. |
Agree with @mikesherov @alberto Would you mind guiding @duncanbeevers with the necessary updates to his PR? |
oh, sorry, I didn't see that PR since it wasn't linked to the issue. @duncanbeevers are you still interested in implementing this? |
@duncanbeevers - thanks! Alright then, I closed #5934 and I think #6216 is ready to merge. |
ok, @duncanbeevers. Thanks for your contribution anyway! |
The
arrow-body-style
rule enforces braceless function bodies when the function consists of a single return statement.When constructing arrow functions which return object literals, the return value must be wrapped in parentheses to force its evaluation as an expression.
The proposed new option enforces a block body with an explicit return value for object literals returned from arrow functions.
Valid
Invalid
The text was updated successfully, but these errors were encountered: