-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
[new cop] Require parentheses #714
Comments
I think that's an excellent idea. There's a rule in the Style Guide that says
And I think we've stayed away from a cop implementation of it because it's so difficult to know what's a DSL and what isn't. But the more limited case of semantically problematic omission of parentheses might be easier to implement a cop for, a lint cop. |
Yeah, that sounds reasonable. I guess we can also have some cop checking for parens used in built-in Ruby DSL methods (like |
Or just enforce parantheses when the line contains one of: and, or, not, &&, ||, ! The order of operations can be tricky to remember, especially if you also use python. |
👍 on this one. I would love to have this. |
[Fix #714] New cop RequireParentheses.
Rubocop, prefers the use of
&&
overand
. This isn't just a syntactic change, it also changes how if statements are evaluated. In the example below, notice inway one
, theinclude?
statement has a space thentuesday
. While,way two
uses parentheses instead of a space.Output
As you can see, the outcome of the if statement is different, and its not immediately obvious why. Furthermore this failure, fails silently which is even worse.
I propose a new cop that enforces the use of parentheses for cases such as this. Thoughts?
The text was updated successfully, but these errors were encountered: