Skip to content

Commit

Permalink
Rename custom rake task to rubocop:autocorrect
Browse files Browse the repository at this point in the history
Follow up #10547.

This PR renames custom rake task from `rubocop:auto_correct`
to `rubocop:autocorrect`.

## Before

```console
rake rubocop                              # Run RuboCop
rake rubocop:auto_correct                 # Autocorrect RuboCop offenses
```

## After

```console
rake rubocop                             # Run RuboCop
rake rubocop:autocorrect                 # Autocorrect RuboCop offenses
```

For compatibility, `rubocop:auto_correct` task is left, but the task is
deprecated and does not display in `rake -T`.

When executed, the following warning will be displayed:

```console
% bundle exec rake rubocop:auto_correct
rubocop:auto_correct task is deprecated; use rubocop:autocorrect task instead.
Running RuboCop...
```
  • Loading branch information
koic committed Jun 11, 2022
1 parent c846697 commit 742f3e4
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
@@ -0,0 +1 @@
* [#10709](https://github.com/rubocop/rubocop/pull/10709): Rename custom rake task from `rubocop:auto_correct` to `rubocop:autocorrect`. ([@koic][])
4 changes: 2 additions & 2 deletions docs/modules/ROOT/pages/integration_with_other_tools.adoc
Expand Up @@ -157,8 +157,8 @@ If you run `rake -T`, the following two RuboCop tasks should show up:

[source,sh]
----
$ rake rubocop # Run RuboCop
$ rake rubocop:auto_correct # Autocorrect RuboCop offenses
$ rake rubocop # Run RuboCop
$ rake rubocop:autocorrect # Autocorrect RuboCop offenses
----

The above will use default values
Expand Down
12 changes: 9 additions & 3 deletions lib/rubocop/rake_task.rb
Expand Up @@ -60,11 +60,17 @@ def setup_ivars(name)
@formatters = []
end

def setup_subtasks(name, *args, &task_block)
def setup_subtasks(name, *args, &task_block) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
namespace(name) do
desc 'Autocorrect RuboCop offenses'
task(:auto_correct, *args) do
warn Rainbow(
'rubocop:auto_correct task is deprecated; use rubocop:autocorrect task instead.'
).yellow
::Rake::Task['rubocop:autocorrect'].invoke
end

task(:auto_correct, *args) do |_, task_args|
desc 'Autocorrect RuboCop offenses'
task(:autocorrect, *args) do |_, task_args|
RakeFileUtils.verbose(verbose) do
yield(*[self, task_args].slice(0, task_block.arity)) if task_block
options = full_options.unshift('--autocorrect-all')
Expand Down
14 changes: 14 additions & 0 deletions spec/rubocop/rake_task_spec.rb
Expand Up @@ -24,6 +24,20 @@
expect(Rake::Task.task_defined?(:lint_lib)).to be true
expect(Rake::Task.task_defined?('lint_lib:auto_correct')).to be true
end

it 'creates a rubocop task and a rubocop autocorrect task' do
described_class.new

expect(Rake::Task.task_defined?(:rubocop)).to be true
expect(Rake::Task.task_defined?('rubocop:autocorrect')).to be true
end

it 'creates a named task and a named autocorrect task' do
described_class.new(:lint_lib)

expect(Rake::Task.task_defined?(:lint_lib)).to be true
expect(Rake::Task.task_defined?('lint_lib:autocorrect')).to be true
end
end

describe 'running tasks' do
Expand Down

0 comments on commit 742f3e4

Please sign in to comment.