Skip to content

Commit

Permalink
Use Cop::Base API for Layout/RedundantLineBreak
Browse files Browse the repository at this point in the history
Follow #7868.

This PR uses `Cop::Base` API for `Layout/RedundantLineBreak`.
  • Loading branch information
koic authored and bbatsov committed Jun 13, 2021
1 parent 9584b01 commit 40ecfcf
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions lib/rubocop/cop/layout/redundant_line_break.rb
Expand Up @@ -42,8 +42,9 @@ module Layout
# # good
# foo(a) { |x| puts x }
#
class RedundantLineBreak < Cop
class RedundantLineBreak < Base
include CheckAssignment
extend AutoCorrector

MSG = 'Redundant line break detected.'

Expand All @@ -55,23 +56,24 @@ def on_send(node)

return unless offense?(node) && !part_of_ignored_node?(node)

add_offense(node)
ignore_node(node)
register_offense(node)
end

private

def check_assignment(node, _rhs)
return unless offense?(node)

add_offense(node)
ignore_node(node)
register_offense(node)
end

def autocorrect(node)
->(corrector) { corrector.replace(node.source_range, to_single_line(node.source).strip) }
def register_offense(node)
add_offense(node) do |corrector|
corrector.replace(node.source_range, to_single_line(node.source).strip)
end
ignore_node(node)
end

private

def offense?(node)
return false if configured_to_not_be_inspected?(node)

Expand Down

0 comments on commit 40ecfcf

Please sign in to comment.