Skip to content

Commit

Permalink
[Fix rubocop#10963] Fix a false positive for Layout/IndentationWidth
Browse files Browse the repository at this point in the history
Fixes rubocop#10963.

This PR fixes a false positive for `Layout/IndentationWidth`
when using aligned empty `else` in pattern matching.
  • Loading branch information
koic committed Aug 25, 2022
1 parent bd42ff6 commit 10cf610
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
@@ -0,0 +1 @@
* [#10963](https://github.com/rubocop/rubocop/issues/10963): Fix a false positive for `Layout/IndentationWidth` when using aligned empty `else` in pattern matching. ([@koic][])
4 changes: 3 additions & 1 deletion lib/rubocop/cop/layout/indentation_width.rb
Expand Up @@ -148,7 +148,9 @@ def on_case_match(case_match)
check_indentation(in_pattern_node.loc.keyword, in_pattern_node.body)
end

check_indentation(case_match.in_pattern_branches.last.loc.keyword, case_match.else_branch)
else_branch = case_match.else_branch&.empty_else_type? ? nil : case_match.else_branch

check_indentation(case_match.in_pattern_branches.last.loc.keyword, else_branch)
end

def on_if(node, base = node)
Expand Down
10 changes: 10 additions & 0 deletions spec/rubocop/cop/layout/indentation_width_spec.rb
Expand Up @@ -915,6 +915,16 @@ def x
RUBY
end

it 'accepts aligned value in `in` clause and `else` is empty' do
expect_no_offenses(<<~'RUBY')
case x
in 42
foo
else
end
RUBY
end

it 'accepts case/in/else laid out as a table' do
expect_no_offenses(<<~RUBY)
case sexp.loc.keyword.source
Expand Down

0 comments on commit 10cf610

Please sign in to comment.