Skip to content

Commit

Permalink
Merge pull request #12882 from nekketsuuu/nekketsuuu-case-in-comment
Browse files Browse the repository at this point in the history
Fix `Layout/CommentIndentation` for comment-only pattern matching
  • Loading branch information
koic committed May 3, 2024
2 parents 9c67edf + c6cf4de commit 7f9595a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#12882](https://github.com/rubocop/rubocop/pull/12882): Fix `Layout/CommentIndentation` for comment-only pattern matching. ([@nekketsuuu][])
2 changes: 1 addition & 1 deletion lib/rubocop/cop/layout/comment_indentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def less_indented?(line)
end

def two_alternatives?(line)
/^\s*(else|elsif|when|rescue|ensure)\b/.match?(line)
/^\s*(else|elsif|when|in|rescue|ensure)\b/.match?(line)
end
end
end
Expand Down
32 changes: 32 additions & 0 deletions spec/rubocop/cop/layout/comment_indentation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@ def m
b
end
# this is accepted
case a
# this is accepted
in 0
#
b
end
# this is accepted
rescue
# this is accepted
ensure
Expand Down Expand Up @@ -196,6 +203,19 @@ def m
#
^ Incorrect indentation detected (column 5 instead of 4).
b
when 2
# this is also accepted
end
case a
# this is accepted
in 0
# so is this
in 1
#
^ Incorrect indentation detected (column 2 instead of 4).
b
in 2
# this is also accepted
end
RUBY

Expand Down Expand Up @@ -225,6 +245,18 @@ def m
when 1
#
b
when 2
# this is also accepted
end
case a
# this is accepted
in 0
# so is this
in 1
#
b
in 2
# this is also accepted
end
RUBY
end
Expand Down

0 comments on commit 7f9595a

Please sign in to comment.