2021-02-05 07:09:31 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-02-03 22:25:57 -05:00
|
|
|
unless Rails.env.production?
|
|
|
|
require 'rubocop/rake_task'
|
2016-05-21 19:27:15 -04:00
|
|
|
|
2015-02-03 22:25:57 -05:00
|
|
|
RuboCop::RakeTask.new
|
2021-09-14 08:10:35 -04:00
|
|
|
|
|
|
|
namespace :rubocop do
|
|
|
|
namespace :todo do
|
|
|
|
desc 'Generate RuboCop todos'
|
2022-03-09 19:08:36 -05:00
|
|
|
task :generate do |_task, args|
|
2021-09-14 08:10:35 -04:00
|
|
|
require 'rubocop'
|
2022-03-09 19:08:36 -05:00
|
|
|
require 'active_support/inflector/inflections'
|
|
|
|
require_relative '../../rubocop/todo_dir'
|
|
|
|
require_relative '../../rubocop/formatter/todo_formatter'
|
|
|
|
|
|
|
|
# Reveal all pending TODOs so RuboCop can pick them up and report
|
|
|
|
# during scan.
|
|
|
|
ENV['REVEAL_RUBOCOP_TODO'] = '1'
|
|
|
|
|
|
|
|
# Save cop configuration like `RSpec/ContextWording` into
|
|
|
|
# `rspec/context_wording.yml` and not into
|
|
|
|
# `r_spec/context_wording.yml`.
|
|
|
|
ActiveSupport::Inflector.inflections(:en) do |inflect|
|
|
|
|
inflect.acronym 'RSpec'
|
|
|
|
inflect.acronym 'GraphQL'
|
|
|
|
end
|
2021-09-14 08:10:35 -04:00
|
|
|
|
|
|
|
options = %w[
|
2022-03-09 19:08:36 -05:00
|
|
|
--parallel
|
|
|
|
--format RuboCop::Formatter::TodoFormatter
|
2021-09-14 08:10:35 -04:00
|
|
|
]
|
|
|
|
|
2022-03-09 19:08:36 -05:00
|
|
|
# Convert from Rake::TaskArguments into an Array to make `any?` work as
|
|
|
|
# expected.
|
|
|
|
cop_names = args.to_a
|
|
|
|
|
2022-05-18 14:08:05 -04:00
|
|
|
todo_dir = RuboCop::TodoDir.new(RuboCop::Formatter::TodoFormatter.base_directory)
|
2022-03-09 19:08:36 -05:00
|
|
|
|
|
|
|
if cop_names.any?
|
|
|
|
# We are sorting the cop names to benefit from RuboCop cache which
|
|
|
|
# also takes passed parameters into account.
|
|
|
|
list = cop_names.sort.join(',')
|
|
|
|
options.concat ['--only', list]
|
|
|
|
|
|
|
|
cop_names.each { |cop_name| todo_dir.inspect(cop_name) }
|
|
|
|
else
|
|
|
|
todo_dir.inspect_all
|
|
|
|
end
|
|
|
|
|
|
|
|
puts <<~MSG
|
|
|
|
Generating RuboCop TODOs with:
|
|
|
|
rubocop #{options.join(' ')}
|
|
|
|
|
|
|
|
This might take a while...
|
|
|
|
MSG
|
|
|
|
|
2021-09-14 08:10:35 -04:00
|
|
|
RuboCop::CLI.new.run(options)
|
2022-03-09 19:08:36 -05:00
|
|
|
|
|
|
|
todo_dir.delete_inspected
|
2021-09-14 08:10:35 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-02-03 22:25:57 -05:00
|
|
|
end
|