Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename custom rake task to rubocop:autocorrect #10709

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -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')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I saw this PR, I was hoping that the rake task would now default to safe auto corrects only.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bbatsov Since this has been merged, but not been released yet, how would you feel about a new PR that adds a rubocop:autocorrect_all task?

The deprecated rubocop:auto_correct task could invoke this one, and the new rubocop:autocorrect could be changed to do safe changes only?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be fine with this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've opened #10746 to solve it.

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