question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

arrow-body-style: rename bloaty requireReturnForObjectLiteral option

See original GitHub issue

Rule: http://eslint.org/docs/rules/arrow-body-style

Note: The old option would be deprecated, not removed, so as to avoid breaking change

The "requireReturnForObjectLiteral" option is unnecessarily longwinded, can it be renamed to "allowLiteralForm"?

This would be clarified by updates to the docs (which I’m currently working on). The old option name could be retained, but deprecated, for backwards compatibility.

For reasoning about the arrow function body, I feel its easier to consider three forms (content from WIP doc update):

Details

Arrow functions have three syntactic forms for their function bodies:

  • Block form: () => { ... }
    • Like a normal function, statements in the function body are wrapped in curly braces.
  • Expression form: () => ...
    • If the function body is not wrapped in braces, and contains a single expression, the result of that expression will be implicitly returned (the return keyword is not required)
  • Literal form: () => ({ key: val, ... })
    • To return an object literal, it must be wrapped in parentheses (otherwise the compiler assumes you’re using block form)
    • Technically, this is a variant of the expression form, but for reasoning purposes it’s easier to think of it as a separate form.

The arrow-body-style rule allows you to define which forms are acceptable for your scripts.

The options documentation then becomes (taken from WIP doc update):

Options

arrow-body-style: [ "level", "pattern", { "option": value } ]
  • level:
    • "off" (default) - disable the rule
    • "warn" - the rule generates warnings
    • "error" - the rule generates errors (exit code 1)
  • pattern:
    • "as-needed" (default) - prevent unnecessary use of braces (if the body is a simple expression, enforce expression form)
    • "always" - mandate block form
    • "never" - mandate expression form
  • option, extra setting for "as-needed" pattern:
    • "allowLiteralForm" - if true (default), allow literal form

Earlier versions of this rule had a "requireReturnForObjectLiteral" option which, if false, would allow the literal form. That option is now deprecated, use the "allowLiteralForm" option instead.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
platinumazurecommented, Jun 17, 2016

Strictly for demonstrative purposes, no, I just misunderstood your proposal. Maybe just edit your first post to make it clear that you want to deprecate the first option? Thanks! On Jun 17, 2016 1:35 PM, “Guy Fraser” notifications@github.com wrote:

The old option should be deprecated, not removed. Is it worth me doing a PR with suggested code changes that handle both old and new option?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/eslint/eslint/issues/6447#issuecomment-226847399, or mute the thread https://github.com/notifications/unsubscribe/AARWetXh7xJX9u7rZ-a8nbrWod855L-7ks5qMujsgaJpZM4I4U4A .

0reactions
aubergine10commented, Jun 17, 2016

Considering the name that was eventually chosen, which makes it sound like the code should be () => (return {foo: 'bar'}) or similar, I can see why there was lots of debate 😛

Read more comments on GitHub >

github_iconTop Results From Across the Web

arrow-body-style - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
eslint arrow-body-style issue - javascript - Stack Overflow
Using arrow-body-style: ["error", "as-needed"] configuration is redundant as it is the default behaviour. You don't need setting it again as ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found