Skip to content

Commit

Permalink
Merge pull request #8766 from dvandersluis/fix-layout-case-indentatio…
Browse files Browse the repository at this point in the history
…n-message

[Fix #8764] Fix `Layout/CaseIndentation` to properly output annotated error messages
  • Loading branch information
koic committed Sep 22, 2020
2 parents 30a3d01 + 7a10d42 commit e18f297
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
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
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 e18f297

Please sign in to comment.