-
-
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
Add a cop for Yoda conditions #4145
Comments
I'm going to work on this one. |
Is |
Might be personal preference depending on the grammar of ones first language, but in English, this is like asking, for example, "is 30 smaller than your age?" instead of "are you over 30?" 😊 |
This seems to be very much a matter of personal preference. There should definitely be a SupportedStyle for requiring Yoda conditions. From https://en.wikipedia.org/wiki/Yoda_conditions:
So there are better ways to protect your code from unintentional assignments in C++, Python, Swift and JS. But not in Ruby (if there is another way, please let me know). So I prefer |
RuboCop's |
Fair enough
Unpractical for a few reasons:
|
I stand corrected regarding |
Guys I've been struggling with this cop for a while. I have working code and green specs, but I feel like I should add more specs and make sure that i didn't miss any edge cases. I'll appreciate any feedback. |
I mentioned this in a review comment for #4014.
A new cop should be added to the
Style
department. It could be calledYodaCondition
and report contructs likeand auto-correct them to
See https://en.wikipedia.org/wiki/Yoda_conditions
The text was updated successfully, but these errors were encountered: