Skip to content

@stylistic/no-mixed-operators isn't compatible with Prettier #889

Closed
xojs/eslint-config-xo
#136

Description

@patrik-csak

I tested this on XO v0.60.0–3.0.2

Given this code:

function getRandomIntInclusive(min, max) {
	const minCeiled = Math.ceil(min);
	const maxFloored = Math.floor(max);
	return Math.floor(Math.random() * (maxFloored - minCeiled + 1) + minCeiled);
}
xo --prettier=compat
✖  4:34  Unexpected mix of * and +. Use parentheses to clarify the intended order of operations.  @stylistic/no-mixed-operators
✖  4:65  Unexpected mix of * and +. Use parentheses to clarify the intended order of operations.  @stylistic/no-mixed-operators

So I add clarifying parentheses:

- return Math.floor(Math.random() * (maxFloored - minCeiled + 1) + minCeiled);
+ return Math.floor((Math.random() * (maxFloored - minCeiled + 1)) + minCeiled);

But Prettier strips them:

- return Math.floor((Math.random() * (maxFloored - minCeiled + 1)) + minCeiled);
+ return Math.floor(Math.random() * (maxFloored - minCeiled + 1) + minCeiled);

Related: prettier/prettier#187

Activity

  1. ctranstrum commented on Jun 20, 2026

    @ctranstrum

    I ran into the same issue with * and ** with prettier as well. Trying to switch to Math.pow() instead of ** only triggered a different rule.

  2. patrik-csak commented on Jul 5, 2026

    @patrik-csak
    ContributorAuthor
  3. snowyukitty commented on Jul 15, 2026

    @snowyukitty

    @patrik-csak's diagnosis is right — the re-enable is in eslint-config-xo. In index.js, prettierCompatibleSpecialRules re-adds @stylistic/no-mixed-operators after spreading eslintConfigPrettier.rules (which already sets it to 0), so it's back on in both prettier: true and prettier: 'compat'.

    It is genuinely an eslint-config-prettier "special rule", but unlike the others in that list it can't be satisfied next to Prettier: Prettier strips the clarifying parentheses the rule asks for (their docs suggest extracting an intermediate variable instead). So the fix is just to drop that one entry from prettierCompatibleSpecialRules and let eslint-config-prettier's 0 stand — non-Prettier XO still enforces the rule via the base config.

    I've written this up with regression tests for all three cases (off in compat, off in true, still enforced by default) and verified it locally — happy to share the patch if it'd save someone time.

    Heads-up for whoever picks it up: xo's test/xo-to-eslint.test.ts asserts this rule is present in the Prettier output, so those two assertions would need to expect the disabled value on the next eslint-config-xo bump.

    Happy to help more here if it's useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions