Skip to content

Mixed operators with same precedence #1071

Closed
@aboyton

Description

@aboyton

The ESLint rule no-mixed-operators is great for making things like

var foo = a && b < 0 || c > 0 || d + 1 === 0;
var bar = a && b || c;

clearer by adding parentheses (rather than having people remember the precedence of && and ||. That said, I'm unconvinced that

var foo = a + b - c

is clearer with parentheses, that is according to this style guide you'd need to write this as

var foo = (a + b) - c

The no-mixed-operators rule has an option for this, allowSamePrecedence and the default is true meaning that var foo = a + b - c is valid code (which I think makes a lot more sense). Is there any reason for having this set to false?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions