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

chore: disable option requireReturnForObjectLiteral in arrow-body-style #214

Merged
merged 1 commit into from
Mar 8, 2024

Conversation

wakamsha
Copy link
Contributor

@wakamsha wakamsha commented Mar 5, 2024

Summary

This PR is a patch for fix #212.

Disable requireReturnForObjectLiteral in arrow-body-style rule. This is because if this option is enabled, return cannot be omitted.

/*
 * eslint arrow-body-style: ["error", "as-needed", {
 *   "requireReturnForObjectLiteral": true
 * }]
 */

const foo = () => ({ foo: 0 });           // 💥Invalid
const bar = () => { return { bar: 0 }; }; // 👍Valid

TO-BE

/*
 * eslint arrow-body-style: ["error", "as-needed", {
 *   "requireReturnForObjectLiteral": false
 * }]
 */

const foo = () => ({ foo: 0 });           // 👍Valid
const bar = () => { return { bar: 0 }; }; // 💥Invalid

References

@wakamsha wakamsha self-assigned this Mar 5, 2024
@wakamsha wakamsha marked this pull request as ready for review March 5, 2024 05:55
@wakamsha wakamsha force-pushed the chore/disable-option-requireReturnForObjectLiteral branch from dafef4d to d73257e Compare March 5, 2024 05:58
@taigakiyokawa
Copy link
Member

@wakamsha Why would you like to disable it? In the previous PR, you said enabling it for considering readability and I have agreed with it.

Considering readability, set requireReturnForObjectLiteral to true.

I can't see the background of this PR from your description.

@wakamsha
Copy link
Contributor Author

wakamsha commented Mar 5, 2024

@taigakiyokawa
Please read the example code in the PR description summary. When this option is enabled, you can't write a function with only one line of processing by omitting return.

It's more readable to omit return for arrow functions that have a return value and only one line of processing. The previous PR didn't consider this.

@taigakiyokawa
Copy link
Member

@wakamsha Ah, I see. I misunderstood you thought writing return is more readable than omitting. Of course, I read your description but I didn't understand what you thought because there is no opinion in the description.

Also, it's not obvious to anyone which one is readable between writing return and omitting. It's a subjective matter and I think it's readable to write return more than omit.

@wakamsha
Copy link
Contributor Author

wakamsha commented Mar 6, 2024

@taigakiyokawa
I understand your point. thank you.
However, I don't want to be forced to return in all our codebase, so I'll disable this option.

@taigakiyokawa
Copy link
Member

@wakamsha OK, I'd like to wait for @thinceller and @tongari07 's opinions. I will agree with you when they've agreed with you.

@tongari07
Copy link
Contributor

tongari07 commented Mar 6, 2024

@wakamsha @taigakiyokawa
I agree to disable this option 👍 As Kiyokawa san said, it is up to the reader to decide if it is readable. So I think it's best to leave it up to the users to enable or disable.

@taigakiyokawa
Copy link
Member

taigakiyokawa commented Mar 8, 2024

@tongari07 This change does not mean that leave it up to users to write or omit return. Disabling requireReturnForObjectLiteral forces users to omit return by default, they cannot write return unless they overwrite the option to be enabled or turn off the rule itself.

@tongari07
Copy link
Contributor

Oh sorry I misunderstood. Still, I agree with wakamsha san.

Copy link
Member

@taigakiyokawa taigakiyokawa left a comment

Choose a reason for hiding this comment

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

OK, I respect what is readable for you all.

@wakamsha wakamsha merged commit 8c4728a into main Mar 8, 2024
10 checks passed
@wakamsha wakamsha deleted the chore/disable-option-requireReturnForObjectLiteral branch March 8, 2024 05:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants