diff --git a/CHANGELOG.md b/CHANGELOG.md index 97a8a82b850..5d197089735 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ * [#8242](https://github.com/rubocop-hq/rubocop/pull/8242): Internal profiling available with `bin/rubocop-profile` and rake tasks. ([@marcandre][]) +### Bug fixes + +* [#8232](https://github.com/rubocop-hq/rubocop/issues/8232): Fix a false positive for `Layout/EmptyLinesAroundAccessModifier` when `end` immediately after access modifier. ([@koic][]) + ## 0.87.1 (2020-07-07) ### Bug fixes diff --git a/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb b/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb index 1e431fe50c4..a9a17c6aefe 100644 --- a/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +++ b/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb @@ -109,6 +109,7 @@ def autocorrect(node) def allowed_only_before_style?(node) if node.special_modifier? + return true if processed_source[node.last_line] == 'end' return false if next_line_empty?(node.last_line) end diff --git a/spec/rubocop/cop/layout/empty_lines_around_access_modifier_spec.rb b/spec/rubocop/cop/layout/empty_lines_around_access_modifier_spec.rb index 20b56ddcee2..bca605caa63 100644 --- a/spec/rubocop/cop/layout/empty_lines_around_access_modifier_spec.rb +++ b/spec/rubocop/cop/layout/empty_lines_around_access_modifier_spec.rb @@ -397,6 +397,14 @@ def test; end end RUBY end + + it "does not register an offense when `end` immediately after #{access_modifier}" do + expect_no_offenses(<<~RUBY) + class Test + #{access_modifier} + end + RUBY + end end %w[public module_function].each do |access_modifier|