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.

Rule Change: Add `onlyOneSimpleParam: boolean` option to `no-confusing-arrow`

See original GitHub issue

What 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:

  1. There are more than 1 arguments or no arguments
  2. 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:closed
  • Created 2 years ago
  • Reactions:5
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
btmillscommented, Feb 1, 2022

Makes sense to me. Since mdjermanovic left a 👍 on the original post, marking as accepted. You’re good to go, @Gautam-Arora24!

1reaction
JLHwungcommented, Jan 31, 2022

@Gautam-Arora24 Sure. I didn’t have bandwidth yet. Please feel free to claim it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

no-confusing-arrow - ESLint - Pluggable JavaScript Linter
This rule warns against using the arrow function syntax in places where it ... onlyOneSimpleParam is a boolean setting that can be true...
Read more >
eslint
49a07c5 feat: add allowParensAfterCommentPattern option to ... 345e70d feat: Add onlyOneSimpleParam option to no-confusing-arrow rule (#15566) (Gautam Arora) ...
Read more >
eslint-config-eslint
Fast, reliable, and secure dependency management.
Read more >
eslint: Versions
Full version history for eslint including change logs. ... 345e70d feat: Add onlyOneSimpleParam option to no-confusing-arrow rule (#15566) (Gautam Arora).
Read more >
Using extenders to make Boolean attributes easy ...
Using extenders, however, you can change how these attributes appear in rules, making life very much easier for business users. For example, an...
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