xojs/xo

Config adjustment: Include more operators in `no-mixed-operators`

fregante opened this issue · 3 comments

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)

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', '??'],
				],
			},
		],

👍 Pull request welcome.

// Conflicts with Prettier: prettier/prettier#3968

That's not a concern here.