Skip to content

Commit bcd874c

Browse files
[major][guide][eslint config] Simplifies no-mixed-operators
- adds warning on mixing `/` and `*` arithmetic operators - removes warnings on mixing `**` and arithmetic operators - removes warning on mixing `in` and `instanceof` - removes warning on mixing `~` with other bitwise operators - removes mixing of assignment operators with comparison operators
1 parent a12dec9 commit bcd874c

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

README.md

+7-3
Original file line numberDiff line numberDiff line change
@@ -2043,7 +2043,8 @@ Other Style Guides
20432043
```
20442044

20452045
<a name="comparison--no-mixed-operators"></a>
2046-
- [15.8](#comparison--no-mixed-operators) When mixing operators, enclose them in parentheses. The only exception is the standard arithmetic operators (`+`, `-`, `*`, & `/`) since their precedence is broadly understood. eslint: [`no-mixed-operators`](https://eslint.org/docs/rules/no-mixed-operators.html)
2046+
- [15.8](#comparison--no-mixed-operators) When mixing operators, enclose them in parentheses. The only exception is the standard arithmetic operators: `+`, `-`, and `**` since their precedence is broadly understood. We recommend enclosing `/` and `*` in parentheses because their precedence can be ambiguous when they are mixed.
2047+
eslint: [`no-mixed-operators`](https://eslint.org/docs/rules/no-mixed-operators.html)
20472048

20482049
> Why? This improves readability and clarifies the developer’s intention.
20492050

@@ -2060,19 +2061,22 @@ Other Style Guides
20602061
return d;
20612062
}
20622063
2064+
// bad
2065+
const bar = a + b / c * d;
2066+
20632067
// good
20642068
const foo = (a && b < 0) || c > 0 || (d + 1 === 0);
20652069
20662070
// good
2067-
const bar = (a ** b) - (5 % d);
2071+
const bar = a ** b - (5 % d);
20682072
20692073
// good
20702074
if (a || (b && c)) {
20712075
return d;
20722076
}
20732077
20742078
// good
2075-
const bar = a + b / c * d;
2079+
const bar = a + (b / c) * d;
20762080
```
20772081

20782082
**[⬆ back to top](#table-of-contents)**

packages/eslint-config-airbnb-base/rules/style.js

+3-7
Original file line numberDiff line numberDiff line change
@@ -293,14 +293,10 @@ module.exports = {
293293
['%', '-'],
294294
['%', '*'],
295295
['%', '/'],
296-
['**', '+'],
297-
['**', '-'],
298-
['**', '*'],
299-
['**', '/'],
300-
['&', '|', '^', '~', '<<', '>>', '>>>'],
301-
['==', '!=', '===', '!==', '>', '>=', '<', '<='],
296+
['/', '*'],
297+
['&', '|', '<<', '>>', '>>>'],
298+
['==', '!=', '===', '!=='],
302299
['&&', '||'],
303-
['in', 'instanceof']
304300
],
305301
allowSamePrecedence: false
306302
}],

0 commit comments

Comments
 (0)