
Inline adoc files when they are included exactly once. Also fix language tags because this inlining gives us better information on what language the code is written in.
85 lines
1.9 KiB
Plaintext
85 lines
1.9 KiB
Plaintext
== Why is this an issue?
|
|
|
|
Shared coding conventions allow teams to collaborate effectively. This rule raises an issue when the use of parentheses with an arrow function does not conform to the configured requirements.
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
With the configured defaults forbidding parentheses
|
|
|
|
[source,javascript]
|
|
----
|
|
var foo = (a) => { /* ... */ }; // Noncompliant; remove parens from arg
|
|
var bar = (a, b) => { return 0; }; // Noncompliant; remove curly braces from body
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,javascript]
|
|
----
|
|
var foo = a => { /* ... */ };
|
|
var bar = (a, b) => 0;
|
|
----
|
|
|
|
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
* [Add|Remove] parentheses around the parameter of this arrow function.
|
|
* Add curly braces and "return" to this arrow function body.
|
|
* Remove curly braces and "return" from this arrow function body.
|
|
|
|
|
|
=== Parameters
|
|
|
|
.parameter_parens
|
|
****
|
|
|
|
----
|
|
False
|
|
----
|
|
|
|
True to require parentheses around parameters. False to forbid them for single parameter.
|
|
****
|
|
.body_braces
|
|
****
|
|
|
|
----
|
|
False
|
|
----
|
|
|
|
True to require curly braces around function body. False to forbid them for single-return bodies.
|
|
****
|
|
|
|
|
|
=== Highlighting
|
|
|
|
The part that needs changing
|
|
|
|
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
=== on 4 Feb 2016, 09:01:13 Elena Vilchik wrote:
|
|
\[~ann.campbell.2] For body we should forbid not parentheses but *curly braces*.
|
|
|
|
----
|
|
var foo = (p1, p2) => { return bar(p1, p2) } // NOK
|
|
var foo = (p1, p2) => bar(p1, p2) // OK
|
|
----
|
|
|
|
And we do that only for function body with one return statement (we should put it in rule description or at least to parameter description).
|
|
|
|
|
|
Also I think it's worth mentioning (in rule or parameter description) that we forbid parentheses around parameters only when there is exactly one parameter.
|
|
|
|
endif::env-github,rspecator-view[]
|