Skip to content

Commit

Permalink
[Fix rubocop#6382] Fix Layout/IndentationWidth with `Layout/EndAlig…
Browse files Browse the repository at this point in the history
…nment` set to start_of_line.

Add spec for if/else in assignment on newline with end alignment set to start of line

Check line_break_before_keyword? for both variable & start_of_line

Update changelog (fixing Siggy's handle)

Co-Authored-By: Max Helmetag <max.helmetag@procore.com>
Co-Authored-By: Michael Siegfried <michael@procore.com>
  • Loading branch information
3 people committed Jan 24, 2019
1 parent 6fdca6d commit 722a7d8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
9 changes: 6 additions & 3 deletions CHANGELOG.md
Expand Up @@ -13,6 +13,7 @@
* [#6351](https://github.com/rubocop-hq/rubocop/pull/6351): Fix a false positive for `Layout/ClosingParenthesisIndentation` when first argument is multiline. ([@antonzaytsev][])
* [#6689](https://github.com/rubocop-hq/rubocop/pull/6689): Support more complex argument patterns on `Rails/Validation` auto-correction. ([@r7kamura][])
* [#6668](https://github.com/rubocop-hq/rubocop/issues/6668): Fix autocorrection for `Style/UnneededCondition` when conditional has the `unless` form. ([@mvz][])
* [#6382](https://github.com/rubocop-hq/rubocop/issues/6382): Fix `Layout/IndentationWidth` with `Layout/EndAlignment` set to start_of_line. ([@dischorde][], [@siegfault][], [@mhelmetag][])

## 0.63.1 (2019-01-22)

Expand Down Expand Up @@ -345,7 +346,7 @@
* [#5881](https://github.com/rubocop-hq/rubocop/pull/5881): Add new `Rails/BulkChangeTable` cop. ([@wata727][])
* [#5444](https://github.com/rubocop-hq/rubocop/pull/5444): Add new `Style/AccessModifierDeclarations` cop. ([@brandonweiss][])
* [#5803](https://github.com/rubocop-hq/rubocop/issues/5803): Add new `Style/UnneededCondition` cop. ([@balbesina][])
* [#5406](https://github.com/rubocop-hq/rubocop/issues/5406): Add new `Layout/ClosingHeredocIndentation` cop. ([@siggymcfried][])
* [#5406](https://github.com/rubocop-hq/rubocop/issues/5406): Add new `Layout/ClosingHeredocIndentation` cop. ([@siegfault][])
* [#5823](https://github.com/rubocop-hq/rubocop/issues/5823): Add new `slashes` style to `Rails/FilePath` since Ruby accepts forward slashes even on Windows. ([@sunny][])
* New cop `Layout/LeadingBlankLines` checks for empty lines at the beginning of a file. ([@rrosenblum][])

Expand Down Expand Up @@ -642,7 +643,7 @@
* [#5177](https://github.com/rubocop-hq/rubocop/pull/5177): Add new `Rails/LexicallyScopedActionFilter` cop. ([@wata727][])
* [#5173](https://github.com/rubocop-hq/rubocop/pull/5173): Add new `Style/EvalWithLocation` cop. ([@pocke][])
* [#5208](https://github.com/rubocop-hq/rubocop/pull/5208): Add new `Rails/Presence` cop. ([@wata727][])
* Allow auto-correction of ClassAndModuleChildren. ([@siggymcfried][], [@melch][])
* Allow auto-correction of ClassAndModuleChildren. ([@siegfault][], [@melch][])

### Bug fixes

Expand Down Expand Up @@ -3689,7 +3690,7 @@
[@walf443]: https://github.com/walf443
[@reitermarkus]: https://github.com/reitermarkus
[@chrishulton]: https://github.com/chrishulton
[@siggymcfried]: https://github.com/siggymcfried
[@siegfault]: https://github.com/siegfault
[@melch]: https://github.com/melch
[@nattfodd]: https://github.com/nattfodd
[@flyerhzm]: https://github.com/flyerhzm
Expand Down Expand Up @@ -3784,3 +3785,5 @@
[@rmm5t]: https://github.com/rmm5t
[@marcotc]: https://github.com/marcotc
[@dazuma]: https://github.com/dazuma
[@dischorde]: https://github.com/dischorde
[@mhelmetag]: https://github.com/mhelmetag
9 changes: 3 additions & 6 deletions lib/rubocop/cop/mixin/end_keyword_alignment.rb
Expand Up @@ -54,12 +54,9 @@ def style_parameter_name
end

def variable_alignment?(whole_expression, rhs, end_alignment_style)
case end_alignment_style
when :variable
!line_break_before_keyword?(whole_expression, rhs)
when :start_of_line
true
end
return if end_alignment_style == :keyword

!line_break_before_keyword?(whole_expression, rhs)
end

def line_break_before_keyword?(whole_expression, rhs)
Expand Down
11 changes: 11 additions & 0 deletions spec/rubocop/cop/layout/indentation_width_spec.rb
Expand Up @@ -514,6 +514,17 @@ def baz
RUBY
end

it 'accepts an if/else in assignment on next line' do
expect_no_offenses(<<-RUBY.strip_indent)
var =
if a
0
else
1
end
RUBY
end

it 'registers an offense for a while' do
expect_offense(<<-RUBY.strip_indent)
var = while a
Expand Down

0 comments on commit 722a7d8

Please sign in to comment.