class Rubocop::DefinitionValidator::Patch
Constants
- ADDED_LINE
- REMOVED_LINE
Public Class Methods
new(original_patch)
click to toggle source
# File lib/rubocop/definition_validator/patch.rb, line 11 def initialize(original_patch) @body = original_patch.body @file = original_patch.file @secure_hash = original_patch.secure_hash end
Public Instance Methods
changed_lines()
click to toggle source
@return [Array<Line>] changed lines
# File lib/rubocop/definition_validator/patch.rb, line 18 def changed_lines line_number = 0 removed_line_offset = 0 lines.each_with_index.inject([]) do |lines, (content, patch_position)| case content when RANGE_INFORMATION_LINE line_number = Regexp.last_match[:line_number].to_i removed_line_offset = 0 when ADDED_LINE line = Rubocop::DefinitionValidator::Line.new( content: content, number: line_number, patch_position: patch_position ) lines << line line_number += 1 removed_line_offset = 0 when REMOVED_LINE line = Rubocop::DefinitionValidator::Line.new( content: content, number: line_number + removed_line_offset, patch_position: patch_position ) lines << line removed_line_offset +=1 when NOT_REMOVED_LINE line_number += 1 removed_line_offset = 0 end lines end end
changed_methods()
click to toggle source
# File lib/rubocop/definition_validator/patch.rb, line 53 def changed_methods lines = changed_lines lines .group_by{|l| l.number} .select{|_, v| v.size == 2} .select{|_, v| t = v.map(&:type); t.include?('-') && t.include?('+')} .select{|_, v| v.all?{|x| x.content =~ /def\s+\w+/}} .map{|line, v| sorted = v.sort_by(&:type) begin ChangedMethod.new(sorted.first, sorted.last, line, @file) rescue Method::InvalidAST => ex warn "Warning: #{ex}\n#{ex.backtrace.join("\n")}"if RuboCop::ConfigLoader.debug end } .compact end