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

Config adjustment: Include more operators in no-mixed-operators #640

Open
fregante opened this issue Oct 2, 2021 · 3 comments
Open

Config adjustment: Include more operators in no-mixed-operators #640

fregante opened this issue Oct 2, 2021 · 3 comments

Comments

@fregante
Copy link
Member

fregante commented Oct 2, 2021

Originally posted in eslint/eslint#14975


What rule do you want to change?

no-mixed-operators:

https://github.com/eslint/eslint/blob/c981fb1994cd04914042ced1980aa86b68ba7be9/lib/rules/no-mixed-operators.js#L25-L40

Please provide some example code that this change will affect:

a || b === c
a ?? b === c

What will the rule do after it's changed?

Suggest a fix:

a || (b === c)
a ?? (b === c)
@fregante
Copy link
Member Author

fregante commented Oct 2, 2021

XO currently just uses the rule’s default, but a change to it was rejected because it would be breaking.

Example config:

		'no-mixed-operators': [
			'error',
			{
				// Customize the defaults to force being explicit about use of null-coalescing operator because its precedence
				// is unintuitive. See: https://eslint.org/docs/rules/no-mixed-operators
				groups: [
					// Conflicts with Prettier: https://github.com/prettier/prettier/issues/3968
					// ["+", "-", "*", "/", "%", "**", "??"],
					['&', '|', '^', '~', '<<', '>>', '>>>', '??'],
					['==', '!=', '===', '!==', '>', '>=', '<', '<=', '??'],
					['&&', '||', '??'],
					['in', 'instanceof', '??'],
				],
			},
		],

@sindresorhus
Copy link
Member

👍 Pull request welcome.

@sindresorhus
Copy link
Member

// Conflicts with Prettier: prettier/prettier#3968

That's not a concern here.

@sindresorhus sindresorhus transferred this issue from xojs/eslint-config-xo Nov 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants