debian-mirror-gitlab/lib/tasks/rubocop.rake

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

68 lines
1.9 KiB
Ruby
Raw Normal View History

2021-03-11 19:13:27 +05:30
# frozen_string_literal: true
2022-05-07 20:08:51 +05:30
# rubocop:disable Rails/RakeEnvironment
2021-03-11 19:13:27 +05:30
2019-02-15 15:39:39 +05:30
unless Rails.env.production?
require 'rubocop/rake_task'
RuboCop::RakeTask.new
2021-11-11 11:23:49 +05:30
namespace :rubocop do
namespace :todo do
desc 'Generate RuboCop todos'
2022-05-07 20:08:51 +05:30
task :generate do |_task, args|
2021-11-11 11:23:49 +05:30
require 'rubocop'
2022-05-07 20:08:51 +05:30
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-11-11 11:23:49 +05:30
options = %w[
2022-05-07 20:08:51 +05:30
--parallel
--format RuboCop::Formatter::TodoFormatter
2021-11-11 11:23:49 +05:30
]
2022-05-07 20:08:51 +05:30
# Convert from Rake::TaskArguments into an Array to make `any?` work as
# expected.
cop_names = args.to_a
2022-07-23 23:45:48 +05:30
todo_dir = RuboCop::TodoDir.new(RuboCop::Formatter::TodoFormatter.base_directory)
2022-05-07 20:08:51 +05:30
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-11-11 11:23:49 +05:30
RuboCop::CLI.new.run(options)
2022-05-07 20:08:51 +05:30
todo_dir.delete_inspected
2021-11-11 11:23:49 +05:30
end
end
end
2019-02-15 15:39:39 +05:30
end
2022-05-07 20:08:51 +05:30
# rubocop:enable Rails/RakeEnvironment