Rule Change: Add `onlyOneSimpleParam: boolean` option to `no-confusing-arrow`
See original GitHub issueWhat rule do you want to change?
no-confusing-arrow
What change to do you want to make?
Generate fewer warnings
How do you think the change should be implemented?
A new option
Example code
() => 1 ? 2 : 3;
(a, b) => 1 ? 2 : 3;
({ a }) => 1 ? 2 : 3;
([ a ]) => 1 ? 2 : 3;
(...a) => 1 ? 2 : 3;
What does the rule currently do for this code?
Warn “Arrow function used ambiguously with a conditional expression.”
What will the rule do after it’s changed?
I propose a new onlyOneSimpleParam
option with false
default value.
When this option is set to true
, the rule will not report any errors if one of the following is satisfied:
- There are more than 1 arguments or no arguments
- The argument is not an identifier
The intention of no-confusing-arrow
is to check whether a BinaryExpression is incorrectly written as an arrow expression. When the arrow contains no argument, the expected BinaryExpression () >= 1
is never valid so we don’t have to throw at all. Actually I think this behaviour should be enabled unconditionally.
When the arrow contains more than one argument: the expected BinaryExpression (a, b) >= 1 ? 2 : 3
is rare use case so we don’t throw
When the arrow param is non-simple: the expected BinaryExpression ({ a, b }) >= 1 ? 2 : 3
is even rarer so we don’t throw.
Note that all the current rule example code gives only an arrow expression with exactly one simple parameter. We could enable this option by default in future majors.
Participation
- I am willing to submit a pull request to implement this change.
Additional comments
Context: https://github.com/babel/babel/pull/14201#discussion_r793178993
Issue Analytics
- State:
- Created 2 years ago
- Reactions:5
- Comments:6 (5 by maintainers)
Top GitHub Comments
Makes sense to me. Since mdjermanovic left a 👍 on the original post, marking as accepted. You’re good to go, @Gautam-Arora24!
@Gautam-Arora24 Sure. I didn’t have bandwidth yet. Please feel free to claim it.