Skip to content

Commit

Permalink
Fix autocorrect for methods not separated by new lines
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromedalbert committed Nov 2, 2024
1 parent 9a51e5e commit f0de600
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/rubocop/cop/obsession/method_order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ module Obsession
# def method_c; ...; end
class MethodOrder < Base
include Helpers
include RangeHelp
include CommentsHelp
include VisibilityHelp
extend AutoCorrector
Expand Down Expand Up @@ -210,15 +209,18 @@ def add_method_offense(method_name, method_index)

def autocorrect(corrector, method, previous_method)
previous_method_range = source_range_with_comment(previous_method)
if buffer.source[previous_method_range.end_pos + 1] == "\n"
previous_method_range = previous_method_range.adjust(end_pos: 1)
end

method_range = source_range_with_comment(method)
if buffer.source[method_range.begin_pos - 1] == "\n"
method_range = method_range.adjust(end_pos: 1)
end

corrector.insert_after(previous_method_range, method_range.source)
corrector.remove(method_range)
end

def source_range_with_comment(node)
range_between(begin_pos_with_comment(node), end_position_for(node) + 1)
end
end
end
end
Expand Down

0 comments on commit f0de600

Please sign in to comment.