xojs / xo

❤️ JavaScript/TypeScript linter (ESLint wrapper) with great defaults
MIT License
7.68k stars 290 forks source link

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

Open fregante opened 3 years ago

fregante commented 3 years ago

Originally posted in https://github.com/eslint/eslint/issues/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 commented 3 years ago

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 commented 3 years ago

👍 Pull request welcome.

sindresorhus commented 3 years ago

// Conflicts with Prettier: https://github.com/prettier/prettier/issues/3968

That's not a concern here.