-
Notifications
You must be signed in to change notification settings - Fork 185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposed linter for mixing logical operators without grouping #1566
Comments
Love it! Would indeed be very useful, for the naive and the advanced users alike.
The one place I have seen people really struggle to make sense of precedence is |
i personally like the |
Related issue coming up in #1656: Currently, the linter marks This technically works as intended because it's parsed as
So perhaps this proposed linter could be something like |
Consider:
I think this is a common pitfall for users not well-versed in logical operator precedence rules (myself included -- I had to look up the precedence once again while writing this post 😸).
At least "
&&
evaluates before||
" appears consistent across languages from what I've seen; this Q&A hints that this order was chosen "to reduce the number of parentheses" (would love a citation on that), while also highlighting an interesting language (Fortress) which declines to set arbitrary operator precedences and instead enforces parentheses in any uncommon combinations:https://softwareengineering.stackexchange.com/q/391263/221381
The above would lint unless the user adds parentheses:
would be the logical equivalents. This would also apply to
&&
/||
.Related: in the Google suite, we have a linter for
!(x == 2)
-->x != 2
. To me, the precedence of!
is clear enough not to need extra parentheses when combined with&&
/||
, so I didn't include it here.The text was updated successfully, but these errors were encountered: