arrow-body-style: rename bloaty requireReturnForObjectLiteral option
See original GitHub issueRule: 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 code1
)- 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"
- iftrue
(default), allow literal formEarlier versions of this rule had a
"requireReturnForObjectLiteral"
option which, iffalse
, would allow the literal form. That option is now deprecated, use the"allowLiteralForm"
option instead.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:2
- Comments:6 (6 by maintainers)
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:
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 😛