Skip to content

Commit

Permalink
Make Layout/IndentArray aware of safe navigation operator
Browse files Browse the repository at this point in the history
  • Loading branch information
hoshinotsuyoshi committed Feb 9, 2019
1 parent e769ca6 commit 5783565
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/rubocop/cop/layout/indent_array.rb
Expand Up @@ -96,6 +96,7 @@ def on_send(node)
check(array_node, left_parenthesis)
end
end
alias on_csend on_send

def autocorrect(node)
AlignmentCorrector.correct(processed_source, node, @column_delta)
Expand Down
12 changes: 12 additions & 0 deletions spec/rubocop/cop/layout/indent_array_spec.rb
Expand Up @@ -203,6 +203,18 @@
RUBY
end

context 'when using safe navigation operator', :ruby23 do
it "registers an offense for 'consistent' indentation" do
expect_offense(<<-RUBY.strip_indent)
receiver&.func([
1
^ Use 2 spaces for indentation in an array, relative to the first position after the preceding left parenthesis.
])
^ Indent the right bracket the same as the first position after the preceding left parenthesis.
RUBY
end
end

it "registers an offense for 'align_brackets' indentation" do
expect_offense(<<-RUBY.strip_indent)
var = [
Expand Down

0 comments on commit 5783565

Please sign in to comment.