Fix undefined method error when exclusion list is empty
What does this MR do and why?
When the Exclude
todo list for a cop is empty the following error was
thrown:
undefined method `grep' for nil:NilClass
gitlab/rubocop/formatter/todo_formatter.rb:95:in `block in create_todos_retaining_exclusions'
Because here the Exclude
key is mapped to nil
and therefore the
default of []
isn't returned by the fetch
method.
MR acceptance checklist
Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
How to set up and validate locally
To reproduce the issue on the master branch create this file
.rubocop_todo/migration/avoid_finalize_background_migration.yml
with
the following contents:
---
Migration/AvoidFinalizeBackgroundMigration:
Exclude:
Then run bundle exec rake rubocop:todo:generate
, the above error will
be thrown.
On this branch, the error will not be thrown and the same has been covered in the specs.