Skip to content

Commit

Permalink
[Fix #8764] Fix Layout/CaseIndentation to properly output annotated…
Browse files Browse the repository at this point in the history
… error messages.
  • Loading branch information
dvandersluis committed Sep 22, 2020
1 parent 30a3d01 commit 7a10d42
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* [#8750](https://github.com/rubocop-hq/rubocop/pull/8750): Fix an incorrect auto-correct for `Style/MultilineWhenThen` when line break for multiple condidate values of `when` statement. ([@koic][])
* [#8754](https://github.com/rubocop-hq/rubocop/pull/8754): Fix an error for `Style/RandomWithOffset` when using a range with non-integer bounds. ([@eugeneius][])
* [#8756](https://github.com/rubocop-hq/rubocop/issues/8756): Fix an infinite loop error for `Layout/EmptyLinesAroundAccessModifier` with `Layout/EmptyLinesAroundBlockBody` when using access modifier with block argument. ([@koic][])
* [#8764](https://github.com/rubocop-hq/rubocop/issues/8764): Fix `Layout/CaseIndentation` not showing the cop name in output messages. ([@dvandersluis][])

### Changes

Expand Down
11 changes: 4 additions & 7 deletions lib/rubocop/cop/layout/case_indentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@ def indentation_width
end

def incorrect_style(when_node)
add_offense(when_node.loc.keyword) do |corrector|
depth = indent_one_step? ? 'one step more than' : 'as deep as'
message = format(MSG, depth: depth, base: style)

add_offense(when_node.loc.keyword, message: message) do |corrector|
detect_incorrect_style(when_node)

whitespace = whitespace_range(when_node)
Expand All @@ -125,12 +128,6 @@ def detect_incorrect_style(when_node)
end
end

def find_message(*)
depth = indent_one_step? ? 'one step more than' : 'as deep as'

format(MSG, depth: depth, base: style)
end

def base_column(case_node, base)
case base
when :case then case_node.location.keyword.column
Expand Down

0 comments on commit 7a10d42

Please sign in to comment.