Cleanup all Rubocop todo files that do not exist
What does this MR do and why?
We track all the files that are violate Rubocop rules in ./rubocop_todo
folder, but sometimes
we rename or delete some code files, without deleting them from the rules.
With this MR, I am cleaning up all the files that don't exist anymore due to deletion of renaming. The script that I used is included in the description here.
New code (updated)
New code is generated using bundle exec rake rubocop:todo:generate
alone
Old Script used
yaml_files = Dir[".rubocop_todo/*/*.yml"]
yaml_files.each do |yaml_file|
parsed_yaml = YAML.load_file(yaml_file)
main_key = parsed_yaml.keys.first
remove_paths = parsed_yaml.values.first["Exclude"].select{ |path| path && !File.exists?(path) }
remove_paths.each do |path|
if path.match('\*')
if !Dir[path].any?
Kernel.system("yq -i 'del(.\"#{main_key}\".Exclude[] | select(. == \"#{path}\"))' #{yaml_file}")
end
else
Kernel.system("yq -i 'del(.\"#{main_key}\".Exclude[] | select(. == \"#{path}\"))' #{yaml_file}")
end
end
end; nil
Closes #340518 (closed).
Update
It turned out bundle exec rake rubocop:todo:generate
does the same, but it take much longer to run.
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Edited by Peter Leitzen