Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upRelax rule: Allow mixing basic operators without parens (+-*/) #816
Comments
feross
added
the
enhancement
label
Mar 7, 2017
This comment has been minimized.
This comment has been minimized.
dougwilson
commented
Mar 7, 2017
|
FWIW, I was meh to -1 on the rule when it was discussed, but not enough to debate it. I ran into one project so far where I had to make a change because of the rule, which was to make |
This comment has been minimized.
This comment has been minimized.
utanapishtim
commented
Mar 7, 2017
|
I think the rule should be kept as is. While I appreciate concerns surrounding the restrictiveness of the rule, I think |
This comment has been minimized.
This comment has been minimized.
|
I'm strongly in favour of relaxing this rule. I think it's the wrong strategy to drag everyone down to the average. If we want to force everyone to write safe code, we should also ban We are in fact heading fast towards just recreating jslint. We have to ask our selfs if standard should be a style guide or if it should also be an error prevention tool. If it should also be an error prevention tool, we have to ask our selfs how experienced the developer is expected to be. We have have to be pragmatic about this. Do we expect developers to know entry-level algebra? Do we expect them to know how to use Promises? Is prototypal inheritance too complex for people to understand? Many people don't understand regular expressions, so maybe we should disallow those? |
This comment has been minimized.
This comment has been minimized.
|
When working with a group of developers on a single project, I've found that clarity in code is more productive then cleverness. Adding parenthesis to signify precedence gives clarity to a non-trivial line of code, even if folks could comprehend it without them. I've rarely been upset at having extra parens as they usually help me break down the logic faster. All that being said, I can see how this rule with all options on could get annoying pretty quick. No one likes feedback that their simple Arithmetic Getting things back on track, here is the rule: And here are the default options: {
"no-mixed-operators": [
"error",
{
"groups": [ // Sets that should require parenthesis for precedence differences
["+", "-", "*", "/", "%", "**"], // Arithmetic Operators
["&", "|", "^", "~", "<<", ">>", ">>>"], // Bitwise Operators
["==", "!=", "===", "!==", ">", ">=", "<", "<="], // Comparison Operators
["&&", "||"], // Logical Operators
["in", "instanceof"] // Relational Operators
],
"allowSamePrecedence": true // ignore for operators that have same precedence
}
]
}Its unfortunate that there is no option for minimum number of operations on a line before checking, as I think that would be a great way to temper this rule. I'm in favor of removing the Arithmetic operators from the rule as it would probably eliminate most of the annoyance. |
This comment has been minimized.
This comment has been minimized.
I agree with this @dougwilson unfortunately there is not a rule/option that does this yet :( Is keeping the Arithmetic operators in this rule worth it for catching these cases? |
This comment has been minimized.
This comment has been minimized.
|
@watson It's clear that you're really frustrated. Sorry if this rule change caused you trouble. I agree that this rule should be relaxed, since we don't want In the future, it would be great to hear your feedback in the "release proposal" issue I always open before putting out a new major release. Here's the one for 9.0.0. It would be really helpful to get feedback then so we can catch issues like this before they go out in a new release. Speaking of which, here is the release proposal for 10.0.0 that would be great to get your feedback on. This release adds two big changes: warn about deprecated Node APIs (so that maybe we can convince Node core this is a better way to handle deprecations than adding console warnings!) and enforce node.js-style callbacks get called with an error or |
feross
added a commit
to standard/eslint-config-standard
that referenced
this issue
Mar 7, 2017
feross
closed this
in
standard/eslint-config-standard@d1c28f4
Mar 7, 2017
This comment has been minimized.
This comment has been minimized.
|
The rule has been relaxed in |
This comment has been minimized.
This comment has been minimized.
Does anyone have a reference I can find as to when this was added to JS? TIL edit: found https://blog.mariusschulz.com/2015/11/24/the-exponentiation-operator-in-javascript |
feross commentedMar 7, 2017
•
edited
There is talk that the preventing the mixing of basic arithmetic operators like
4 + 5 * 2is too restrictive. This was released instandardv9. Currentlystandardrequires that4 + 5 * 2be written as4 + (5 * 2).There was discussion about this in the original issue here: #566 (comment) and it came up on Twitter here: https://twitter.com/wa7son/status/838310839560060928
I think this is acceptable. I personally care more about parens for the other precedence levels which are much less well-understood.
Also, note: When adding a new rule to
standardthat we all agree is worth having, I usually prefer to keep all the options on (so it's as restrictive as is reasonable), and then to relax the rule in a patch version as folks bring up issues like this one.So this is actually feedback that I was expecting😉 Please share thoughts below.