Skip to content

Commit

Permalink
Support RuboCop v0.85.0 and later
Browse files Browse the repository at this point in the history
Use `Rubocop::Cop::Team#mobilize` instead of `Rubocop::Cop::Team.new`
if RuboCop version is 0.85.0 and later because RuboCop changed `Team` API
at v0.85.0.
ref. rubocop/rubocop#8030
  • Loading branch information
yujideveloper committed Jun 4, 2020
1 parent 0a2f99f commit f5589f6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
23 changes: 17 additions & 6 deletions lib/pronto/rubocop/offense_line.rb
Expand Up @@ -56,12 +56,23 @@ def original_lines
end

def autocorrect_team
@autocorrect_team ||= ::RuboCop::Cop::Team.new(
::RuboCop::Cop::Registry.new([cop]),
patch_cop.rubocop_config,
auto_correct: true,
stdin: true,
)
@autocorrect_team ||=
if ::RuboCop::Cop::Team.respond_to?(:mobilize)
# rubocop v0.85.0 and later
::RuboCop::Cop::Team.mobilize(
::RuboCop::Cop::Registry.new([cop]),
patch_cop.rubocop_config,
auto_correct: true,
stdin: true,
)
else
::RuboCop::Cop::Team.new(
::RuboCop::Cop::Registry.new([cop]),
patch_cop.rubocop_config,
auto_correct: true,
stdin: true,
)
end
end

def cop
Expand Down
8 changes: 7 additions & 1 deletion lib/pronto/rubocop/patch_cop.rb
Expand Up @@ -60,7 +60,13 @@ def offenses
end

def team
@team ||= ::RuboCop::Cop::Team.new(registry, rubocop_config)
@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
end
end
Expand Down

0 comments on commit f5589f6

Please sign in to comment.