no-extra-parens: Allow brackets in expressions that depend on operator precedence
See original GitHub issueWhat rule do you want to change? no-extra-parens
Does this change cause the rule to produce more or fewer warnings? fewer
How will the change be implemented? (New option, new default behavior, etc.)? Either new option or new default behaviour. Option may be less contraversial
Please provide some example code that this change will affect:
const cost = fixed + (monthly * 12);
What does the rule currently do for this code? Warn about the “Unnecessary” parentheses
What will the rule do after it’s changed? No warning
Are you willing to submit a pull request to implement this change? I could try.
The justification for this change comes from the results of our readability experiment that looks for empirical data on how coding constructs affect readability. The code above was included in a series of blind A/B tests where we measured the time taken by developers to read a code snippet and whether they could correctly predict its outcome.
We found a statistically significant improvement in both speed of reading the code and accuracty of prediction when the parentheses were included in the code. Whilst they are technically un-necessary if operator precedence is followed, it seems clear that adding them improves readability.
The full results of the experiment are available here:
https://howreadable.netlify.com/results/#operator-precedence
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
It’s ‘binary’ as - expression with a binary operator (that requires two operands, unlike unary and ternary operators). I guess it could be confused with bitwise operators which work on the binary representation of the data?
It makes sense to me, as the default settings can be seen as a recommendation, but that would be a breaking change and it might be confusing because the rule by default disallows all parens (except those that are the responsibility of other rules).
Just to add, ESLint has also a core rule to basically enforce these parentheses: no-mixed-operators