diff --git a/lib/pronto/rubocop/patch_cop.rb b/lib/pronto/rubocop/patch_cop.rb index 739b5c6..1190e8a 100644 --- a/lib/pronto/rubocop/patch_cop.rb +++ b/lib/pronto/rubocop/patch_cop.rb @@ -31,7 +31,10 @@ def processed_source end def registry - @registry ||= ::RuboCop::Cop::Registry.new(RuboCop::Cop::Cop.all) + @registry ||= ::RuboCop::Cop::Registry.new( + # keep support of older Rubocop versions + RuboCop::Cop.const_defined?(:Registry) ? RuboCop::Cop::Registry.all : RuboCop::Cop::Cop.all + ) end def rubocop_config @@ -58,8 +61,14 @@ def path end def offenses - team - .inspect_file(processed_source) + # 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 diff --git a/spec/pronto/rubocop/patch_cop_spec.rb b/spec/pronto/rubocop/patch_cop_spec.rb index 0cbf83a..fbae382 100644 --- a/spec/pronto/rubocop/patch_cop_spec.rb +++ b/spec/pronto/rubocop/patch_cop_spec.rb @@ -11,7 +11,8 @@ let(:runner) { double :runner } let(:ast) { double :ast, each_node: nil } let(:processed_source) { double :processed_source, ast: ast } - let(:team) { double :team, inspect_file: [offense] } + let(:team) { double :team, investigate: offenses } + let(:offenses) { double :offenses, offenses: [offense] } let(:offense_location) { double :location, first_line: 42, last_line: 43 } let(:offense) { double :offense, disabled?: false, location: offense_location } let(:offense_line) { double :offense_line, message: 'Err' }