Fix clobbering inherit_from
additions when not using Namespaces in the configs
#3421
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
The current implementation of
load_file
will load the hash from a config, then apply the base_configs to that hash, before converting it to a properConfig
object, which means we are comparing a vanillaHash
with aConfig
, so one will have the converted namespace Cop names, and the other will not. This can clobber inherited configuration since merging will happen in resolve_inheritance, but will just keep the keys from both and then whenadd_missing_namespaces
is called, one will be dropped.Since
Config
inherits fromHash
, there shouldn't be a problem with doing theresolve_*
methods after theconfig = Config.new
line since all the normal Hash methods are available (.delete specifically).Example (before this change)
Given the following files:
.rubocop.yml
base.yml
.rubocop.yml
is loaded through theload_file
methodit, in turn, loads
base.yml
when called inbase_configs
fromresovle_inheritance
When
add_missing_namespaces
is called onbase.yml
, it converts{"LineLength" => {"Max" => 120}}
to have"Metrics/LineLength"
, and deletes old"LineLength"
keyThe unconverted hash of '.rubocop.yml
is then merged with the converted
base.yml`, and so the following hash exists:When
add_missing_namespaces
is called on the now merged.rubocop.yml
config, it will delete the changes from"Metrics/LineLength" => {"Max" => 120}
when converting"LineLength"
to have a namespace, and the defaultLineLength
max value will be used instead.Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).and description in grammatically correct, complete sentences.