From 742f3e4729988ed5663b0a62c46cdcf6201cafb6 Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Sat, 11 Jun 2022 14:38:10 +0900 Subject: [PATCH] Rename custom rake task to `rubocop:autocorrect` 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... ``` --- ...name_custom_rake_task_to_rubocop_autocorrect.md | 1 + .../ROOT/pages/integration_with_other_tools.adoc | 4 ++-- lib/rubocop/rake_task.rb | 12 +++++++++--- spec/rubocop/rake_task_spec.rb | 14 ++++++++++++++ 4 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 changelog/change_rename_custom_rake_task_to_rubocop_autocorrect.md diff --git a/changelog/change_rename_custom_rake_task_to_rubocop_autocorrect.md b/changelog/change_rename_custom_rake_task_to_rubocop_autocorrect.md new file mode 100644 index 00000000000..8ac6c4ea7f5 --- /dev/null +++ b/changelog/change_rename_custom_rake_task_to_rubocop_autocorrect.md @@ -0,0 +1 @@ +* [#10709](https://github.com/rubocop/rubocop/pull/10709): Rename custom rake task from `rubocop:auto_correct` to `rubocop:autocorrect`. ([@koic][]) diff --git a/docs/modules/ROOT/pages/integration_with_other_tools.adoc b/docs/modules/ROOT/pages/integration_with_other_tools.adoc index b64ed3802d8..1fbdbe0bfbb 100644 --- a/docs/modules/ROOT/pages/integration_with_other_tools.adoc +++ b/docs/modules/ROOT/pages/integration_with_other_tools.adoc @@ -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 diff --git a/lib/rubocop/rake_task.rb b/lib/rubocop/rake_task.rb index 8483acfccc7..30ebcf0f79b 100644 --- a/lib/rubocop/rake_task.rb +++ b/lib/rubocop/rake_task.rb @@ -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') diff --git a/spec/rubocop/rake_task_spec.rb b/spec/rubocop/rake_task_spec.rb index f9f7b611994..6d413347b67 100644 --- a/spec/rubocop/rake_task_spec.rb +++ b/spec/rubocop/rake_task_spec.rb @@ -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