-
-
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 Style/IndentAssignment Cop #2410
Conversation
bf3d0af
to
0a605d6
Compare
require 'spec_helper' | ||
|
||
describe Astrolabe::Node do | ||
context '#asgn_method_call?' do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this ought to be describe
, not context
.
0803d23
to
18752c1
Compare
@jonas054 updated to address your comment |
The code looks good, but there's something wrong. The build fails. Please add spec example(s) that fails the same way that the rubocop self-inspection currently does (if you see what I mean), and fix. |
18752c1
to
f8bf8f3
Compare
@jonas054 The issue was some additional comparison operators that |
👍 Looks good but you must rebase on top of the latest |
f8bf8f3
to
d602438
Compare
@jonas054 rebased on top of |
@@ -37,8 +37,11 @@ def single_line? | |||
!multiline? | |||
end | |||
|
|||
COMPARISON_OPERATORS = [:==, :===, :!=, :<=, :>=, :>, :<, :<=>] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be frozen and possibly placed higher up the class def. I don't like mixing constants with method definitions.
I don't see a test showing that this won't generate an offense: ala = if bala
tralala
end |
Nice! |
Thanks for fixing my bugs! |
When assignments span multiple lines, this cop enforces proper indentation on the right-hand-side of the expression. It only corrects the first line, as the remaining lines can be corrected by other cops such as `Style/IndentationConsistency`. # bad value = if foo 'bar' else 'biz' end # good value = if foo # corrected/accepted 'bar' else 'biz' end I have also added a fix to `Astrolabe::Node#asgn_method_call?`. It used to consider comparison operators such as `!=` and `===` as assignments - which they are not. There were also no tests for this method so I've added them.
d602438
to
05d15fd
Compare
@bbatsov addressed your comments and rebased off master. |
Add Style/IndentAssignment Cop
👍 |
This is a prequel to #2361. It is enabled by default and properly fixes the auto-correct output that
MultilineAssignmentLayout
produces.When assignments span multiple lines, this cop enforces proper indentation on the right-hand-side of the expression. It only corrects the first line, as the remaining lines can be corrected by other cops such as
Style/IndentationConsistency
.I have also added a fix to
Astrolabe::Node#asgn_method_call?
. It used to consider!=
method calls as assignments - which they are not. There were also no tests for this method so I've added them.