Skip to content

Commit

Permalink
Fix Rubocop deprecated method warnings
Browse files Browse the repository at this point in the history
* `Cop.all` is deprecated. Use `Registry.all` instead.
* `inspect_file` is deprecated. Use `investigate` instead.
  • Loading branch information
ramil350 committed Aug 19, 2024
1 parent 5fcb08d commit 15eabe3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
15 changes: 12 additions & 3 deletions lib/pronto/rubocop/patch_cop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion spec/pronto/rubocop/patch_cop_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
Expand Down

0 comments on commit 15eabe3

Please sign in to comment.