diff --git a/.ci/fixtures/new_provider_sync.yml b/.ci/fixtures/new_provider_sync.yml index 0bae3b21a5e73d123e3c85c4557cda744da1175d..63c67d6cb8fb4e4ef214700e780313efe3db7cf9 100644 --- a/.ci/fixtures/new_provider_sync.yml +++ b/.ci/fixtures/new_provider_sync.yml @@ -5,3 +5,7 @@ Gemfile: - gem: 'puppet-resource_api' spec/spec_helper.rb: mock_with: ':rspec' +.rubocop.yml: + default_configs: + Performance/CaseWhenSplat: + Enabled: false diff --git a/.ci/test_script.sh b/.ci/test_script.sh index 0484889077544d0a2ec4da10b9e55aba8d3eca60..e1535f90c0c1779065532d1acd95ce37c0e26b7f 100755 --- a/.ci/test_script.sh +++ b/.ci/test_script.sh @@ -13,7 +13,9 @@ pdk new module new_module --template-url="file://$TEMPLATE_PR_DIR" --template-re pushd new_module grep template < metadata.json cp "$TEMPLATE_PR_DIR/.ci/fixtures/new_provider_sync.yml" ./.sync.yml +grep -A 1 "Performance/CaseWhenSplat" ./.rubocop.yml | grep -q "true" # Ensure that the template is applied pdk update --force +grep -A 1 "Performance/CaseWhenSplat" ./.rubocop.yml | grep -q "false" # Ensure that the update command changes the template pdk new class new_module pdk new defined_type test_type pdk new fact test_fact || true # not available in pdk 1.18 yet diff --git a/moduleroot/.rubocop.yml.erb b/moduleroot/.rubocop.yml.erb index d93cfc238ec42fd497f3575ec4940ed24135990d..d12fe20c7fba0949738840eb23afa5735190becb 100644 --- a/moduleroot/.rubocop.yml.erb +++ b/moduleroot/.rubocop.yml.erb @@ -56,11 +56,13 @@ dynamic_path = File.absolute_path(File.join(base_path, "defaults-#{version}.yml" default_path = File.absolute_path(File.join(base_path, "defaults-#{default_version}.yml")) path = File.exist?(dynamic_path) ? dynamic_path : default_path +# The following block builds default_enabled_cops and default_pending_cops based on the existing values at defaults-<current_version>.yml, which usually lives at ∼/rubocop/ require 'yaml' config_defaults = YAML.load(File.read(path)) default_enabled_cops = config_defaults[:default_enabled_cops] || [] default_pending_cops = config_defaults[:default_pending_cops] || [] +# This line builds cop_configs based on the values existing at profile, which was previously configured to retrieve the values of a specific profile in config_defaults.yml cop_configs = (profile['enabled_cops'] || {}) if cop_configs == 'all' @@ -71,12 +73,20 @@ else enabled_cops = [] end +# Create a filtered list of enabled cops that should be disabled. +disabled_cops = enabled_cops.select { |c| configs[c] && configs[c]['Enabled'] == false } + +# The following block builds the final configuration based on the values of enabled_cops, default_enabled_cops, default_pending_cops, and cop_configs (enabled_cops & default_enabled_cops).sort.each { |c| configs[c] ||= cop_configs[c] if cop_configs[c] } (enabled_cops - default_enabled_cops).sort.each { |c| configs[c] ||= cop_configs[c] || {}; configs[c]['Enabled'] = true } (default_enabled_cops - enabled_cops).sort.each { |c| configs[c] ||= cop_configs[c] || {}; configs[c]['Enabled'] = false } # force set pending cops to something to avoid the messages -(default_pending_cops & enabled_cops).sort.each { |c| configs[c] ||= cop_configs[c] if cop_configs[c]; configs[c]['Enabled'] = true } +(default_pending_cops & enabled_cops).sort.each { |c| configs[c] ||= cop_configs[c] if cop_configs[c]; configs[c]['Enabled'] = true } (default_pending_cops - enabled_cops).sort.each { |c| configs[c] = { 'Enabled' => false } } + +# Set overriden cops to false if 'Enabled: false'. This can be the case when users override default behaviour via .sync.yml +(disabled_cops).sort.each { |c| configs[c] = { 'Enabled' => false } } + -%> <%= YAML.dump(configs) -%>