Skip to content

Commit

Permalink
[Fix #10780] Fix an error when using rubocop:auto_correct rake task
Browse files Browse the repository at this point in the history
Fixes #10780.

This commit fixes the following error when using `rubocop:auto_correct`
deprecated custom rake task.

```console
% bundle exec rake lint:rubocop:auto_correct
rake aborted!
NoMethodError: undefined method `Rainbow' for
#<RuboCop::RakeTask:0x000000010b7a9020 @name=:rubocop, @verbose=true,
@fail_on_error=true, @patterns=[], @requires=[], @options=[], @Formatters=[]>

          warn Rainbow(
               ^^^^^^^
```

And it fixes the following error that occur after that.

```console
% bundle exec rake lint:rubocop:auto_correct
rubocop:auto_correct task is deprecated; use rubocop:autocorrect task or
rubocop:autocorrect_all task instead.
rake aborted!
Don't know how to build task 'rubocop:autocorrect' (See the list of
available tasks with `rake --tasks`)
/Users/koic/src/github.com/rubocop/rubocop/lib/rubocop/rake_task.rb:81:in
`block (2 levels) in setup_subtasks'
/Users/koic/.rbenv/versions/3.1.2/bin/bundle:25:in `load'
/Users/koic/.rbenv/versions/3.1.2/bin/bundle:25:in `<main>'
Tasks: TOP => lint:rubocop:auto_correct
(See full trace by running task with --trace)
```
  • Loading branch information
koic committed Jul 2, 2022
1 parent 5e82448 commit 9ebb61a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
@@ -0,0 +1 @@
* [#10780](https://github.com/rubocop/rubocop/issues/10780): Fix an error when using `rubocop:auto_correct` deprecated custom rake task. ([@koic][])
6 changes: 5 additions & 1 deletion lib/rubocop/rake_task.rb
Expand Up @@ -73,11 +73,15 @@ def setup_subtasks(name, *args, &task_block) # rubocop:disable Metrics/AbcSize,
namespace(name) do
# rubocop:todo Naming/InclusiveLanguage
task(:auto_correct, *args) do
require 'rainbow'
warn Rainbow(
'rubocop:auto_correct task is deprecated; ' \
'use rubocop:autocorrect task or rubocop:autocorrect_all task instead.'
).yellow
::Rake::Task['rubocop:autocorrect'].invoke
RakeFileUtils.verbose(verbose) do
yield(*[self, task_args].slice(0, task_block.arity)) if task_block
perform('--autocorrect')
end
end
# rubocop:enable Naming/InclusiveLanguage

Expand Down

0 comments on commit 9ebb61a

Please sign in to comment.