Skip to content

RuboCop: Split `.rubocop_manual_todo.yml` into `.rubocop_todo/**/*.yml`

Peter Leitzen requested to merge pl-rubocop-todo-directory into master

What does this MR do and why?

  1. RuboCop: Split .rubocop_manual_todo.yml into .rubocop_todo/**/*.yml
  2. Enhance rake rubocop:todo:generate to split TODOs into separate files

This MR moves all RuboCop configuration from the large .rubocop_manual_todo.yml into smaller more focused files within .rubocop_todo/**/*.yml.

This step enables us to split .rubocop_todo.yml later which is very likely needed if we start using rake rubocop:todo:generate because it will produce a huge .rubocop_todo.yml (due to much higher "exclude limit").

Contributes to #294273 (closed).

Verification of rubocop --show-cops

The output of bundle exec rubocop --show-cops did not change before and after this MR (with and without revealing todos) which was expected:

Before

$ export REVEAL_RUBOCOP_TODO=0
$ bundle exec rubocop --show-cops | md5sum
dbf75c20c512b4c25f263650c1e205cd  -

$ export REVEAL_RUBOCOP_TODO=1
$ bundle exec rubocop --show-cops | md5sum
6d1a0f5e6119f7440839fc65fbd823c8  -

After

$ export REVEAL_RUBOCOP_TODO=0
$ bundle exec rubocop --show-cops | md5sum
dbf75c20c512b4c25f263650c1e205cd  -

$ export REVEAL_RUBOCOP_TODO=1
$ bundle exec rubocop --show-cops | md5sum
6d1a0f5e6119f7440839fc65fbd823c8  -

How to set up and validate locally

export REVEAL_RUBOCOP_TODO=1
bundle exec rubocop --show-cops

export REVEAL_RUBOCOP_TODO=0
bundle exec rubocop --show-cops

bundle exec rubocop <file>

Making of

The YAML files have been generated via the following script:

require "fileutils"
require "yaml"
require "active_support/all"

ActiveSupport::Inflector.inflections(:en) do |inflect|
  inflect.acronym 'RSpec'
  inflect.acronym 'GraphQL'
end

def dump_into_file(cop_name, config)
  filename = File.expand_path(File.join(".rubocop_todo/#{cop_name.underscore}.yml"), __dir__)

  FileUtils.mkdir_p(File.dirname(filename))

  File.write(filename, YAML.dump(cop_name => config))
end

yaml = YAML.load_file(".rubocop_manual_todo.yml")
yaml.each do |cop_name, config|
  dump_into_file(cop_name, config)
end

Later, rake rubocop:generate:todo could use the very same technique to split the auto-generated .rubocop_todo.yml into .rubocop_todo/**/*.yml too. Note, with this is approach we are losing YAML comments generated by RuboCop but I think this is acceptable.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Takuya Noguchi

Merge request reports

Loading