class Pronto::Rubocop::PatchCop
Attributes
Public Class Methods
Source
# File lib/pronto/rubocop/patch_cop.rb, line 8 def initialize(patch, runner) @patch = patch @runner = runner end
Public Instance Methods
Source
# File lib/pronto/rubocop/patch_cop.rb, line 13 def messages return [] unless valid? offenses .map { |offense| first_relevant_message(patch, offense) } .compact end
Source
# File lib/pronto/rubocop/patch_cop.rb, line 21 def processed_source @processed_source ||= begin processed_source = ::RuboCop::ProcessedSource.from_file( path, rubocop_config.target_ruby_version ) processed_source.registry = registry if processed_source.respond_to?(:registry=) processed_source.config = rubocop_config if processed_source.respond_to?(:config=) processed_source end end
Source
# File lib/pronto/rubocop/patch_cop.rb, line 33 def registry @registry ||= ::RuboCop::Cop::Registry.new(all_cops) end
Source
# File lib/pronto/rubocop/patch_cop.rb, line 37 def rubocop_config @rubocop_config ||= begin store = ::RuboCop::ConfigStore.new store.options_config = ENV['RUBOCOP_CONFIG'] if ENV['RUBOCOP_CONFIG'] store.for(path) end end
Private Instance Methods
Source
# File lib/pronto/rubocop/patch_cop.rb, line 49 def all_cops # keep support of older Rubocop versions if RuboCop::Cop.const_defined?(:Registry) && RuboCop::Cop::Registry.respond_to?(:all) RuboCop::Cop::Registry.all else RuboCop::Cop::Cop.all end end
Source
# File lib/pronto/rubocop/patch_cop.rb, line 97 def first_relevant_line(patch, offense) patch.added_lines.detect do |line| offense_includes?(offense, line.new_lineno) end end
Source
# File lib/pronto/rubocop/patch_cop.rb, line 103 def first_relevant_message(patch, offense) offending_line = first_relevant_line(patch, offense) return nil unless offending_line OffenseLine.new(self, offense, offending_line).message end
Source
# File lib/pronto/rubocop/patch_cop.rb, line 82 def offense_includes?(offense, line_number) offense_range = (offense.location.first_line..offense.location.last_line) offense_range.include?(line_number) end
Source
# File lib/pronto/rubocop/patch_cop.rb, line 69 def offenses # keep support of older Rubocop versions if team.respond_to?(:investigate) offenses = team.investigate(processed_source).offenses else offenses = team.inspect_file(processed_source) end offenses .sort .reject(&:disabled?) end
Source
# File lib/pronto/rubocop/patch_cop.rb, line 65 def path @path ||= patch.new_file_full_path.to_s end
Source
# File lib/pronto/rubocop/patch_cop.rb, line 87 def team @team ||= if ::RuboCop::Cop::Team.respond_to?(:mobilize) # rubocop v0.85.0 and later ::RuboCop::Cop::Team.mobilize(registry, rubocop_config) else ::RuboCop::Cop::Team.new(registry, rubocop_config) end end
Source
# File lib/pronto/rubocop/patch_cop.rb, line 58 def valid? return false if rubocop_config.file_to_exclude?(path) return true if rubocop_config.file_to_include?(path) runner.ruby_file?(path) end