Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Cop::Base API for Layout/RedundantLineBreak #9875

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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