Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove no-confusing-arrow because of the deprecation of formatting rules #276

Merged
merged 4 commits into from
Jul 17, 2024

Conversation

ybiquitous
Copy link
Member

@ybiquitous ybiquitous commented Jun 21, 2024

Which issue, if any, is this issue related to?

None.

Is there anything in the PR that needs further explanation?

First, this rule was deprecated in ESLint v8.53.0. The alternative is the third-party plugin @stylistic/eslint-plugin-js.

Second, I sometimes feel annoyed by this rule. For example, see:

const result = () => (type === 'foo' ? foo() : bar());
/*             ^^ Arrow function used ambiguously with a conditional expression [no-confusing-arrow] */

In this case, I think it's readable enough, thanks to () around the function body.
So, I think this rule is no longer necessary for this shared config.

Ref:

Note

This rule was added in #74.

…rules

First, this rule was deprecated in ESLint v8.53.0.
The alternative is the third-party plugin `@stylistic/eslint-plugin-js`.

Second, I sometimes feel annoying on this rule. For example, see:

```js
const result = () => (type === 'foo' ? foo() : bar());
/*             ^^ Arrow function used ambiguously with a conditional expression [no-confusing-arrow] */
```

In this case, I think it's enough readable, thanks to `()` around the function body.
So, I think this rule is no longer necessary in this shared config.

Ref:
- https://eslint.org/docs/latest/rules/no-confusing-arrow
- https://eslint.org/blog/2023/10/deprecating-formatting-rules
- https://eslint.style/packages/js
@Mouvedia
Copy link
Member

Mouvedia commented Jun 23, 2024

My problem is that it conflicts with prettier.

thanks to () around the function body

There's an option for that: { "allowParens": true }

@ybiquitous
Copy link
Member Author

@Mouvedia Can you tell me how to reproduce the conflict with Prettier?

@Mouvedia
Copy link
Member

Try

			const fix = () =>
				(messageType === 'expected' ? fontFamilyNode.addQuotes() : fontFamilyNode.removeQuotes());

It will be reformatted.

@ybiquitous
Copy link
Member Author

@Mouvedia Sorry, I didn't understand what you meant. The example code you posted is a problem of Prettier, not no-confusing-arrow, right?

@Mouvedia
Copy link
Member

Mouvedia commented Jun 24, 2024

If you were using { "allowParens": true } instead of removing the rule then it would conflict with prettier because prettier removes the parentheses. If you remove the rule, it's irrelevant.

@ybiquitous
Copy link
Member Author

Ah, I now understand. Assuming the following example:

/*eslint-disable no-unused-vars, no-undef*/

/*eslint no-confusing-arrow: ["error", {"allowParens": true}]*/

const fix = () =>
	(messageType === 'expected' ? fontFamilyNode.addQuotes() : fontFamilyNode.removeQuotes());

Prettier removes (...) from the arrow function body:

const fix = () =>
-	(messageType === 'expected' ? fontFamilyNode.addQuotes() : fontFamilyNode.removeQuotes());
+	messageType === 'expected' ? fontFamilyNode.addQuotes() : fontFamilyNode.removeQuotes();

Then, ESLint emits an error:

const fix = () =>
/*          ^^ Arrow function used ambiguously with a conditional expression */
	messageType === 'expected' ? fontFamilyNode.addQuotes() : fontFamilyNode.removeQuotes();

By the way, if an arrow function is within a single line, Prettier doesn't format the code:

const fix2 = () => (type === 'expected' ? addQuotes() : removeQuotes());

In summary, I think removing no-confusing-arrow is better to prevent any confusion.

@Mouvedia
Copy link
Member

By the way, if an arrow function is within a single line, Prettier doesn't format the code

Good to know.

@ybiquitous
Copy link
Member Author

I'm merging this PR since there are no objections.

@ybiquitous ybiquitous merged commit 5c631c6 into main Jul 17, 2024
5 checks passed
@ybiquitous ybiquitous deleted the remove-no-confusing-arrow branch July 17, 2024 12:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants