diff --git a/lib/package_protections.rb b/lib/package_protections.rb index db9a358..24f88c2 100644 --- a/lib/package_protections.rb +++ b/lib/package_protections.rb @@ -118,15 +118,6 @@ def self.rubocop_yml(root_pathname: Bundler.root) Private.rubocop_yml(root_pathname: root_pathname) end - # - # Do not use this method -- it's meant to be used by Rubocop cops to get directory-specific - # parameters without needing to have directory-specific .rubocop.yml files. - # - sig { params(identifier: Identifier).returns(T::Hash[T.untyped, T.untyped]) } - def self.private_cop_config(identifier) - Private.private_cop_config(identifier) - end - sig { void } def self.bust_cache! Private.bust_cache! diff --git a/lib/package_protections/private.rb b/lib/package_protections/private.rb index b8aefe1..86913f6 100644 --- a/lib/package_protections/private.rb +++ b/lib/package_protections/private.rb @@ -115,23 +115,12 @@ def self.get_package_with_name(name) sig { void } def self.bust_cache! @protected_packages_indexed_by_name = nil - @private_cop_config = nil PackageProtections.config.bust_cache! # This comes explicitly after `PackageProtections.config.bust_cache!` because # otherwise `PackageProtections.config` will attempt to reload the client configuratoin. @loaded_client_configuration = false end - sig { params(identifier: Identifier).returns(T::Hash[T.untyped, T.untyped]) } - def self.private_cop_config(identifier) - @private_cop_config ||= T.let(@private_cop_config, T.nilable(T::Hash[T.untyped, T.untyped])) - @private_cop_config ||= begin - protected_packages = all_protected_packages - protection = T.cast(PackageProtections.with_identifier(identifier), PackageProtections::RubocopProtectionInterface) - protected_packages.to_h { |p| [p.name, protection.custom_cop_config(p)] } - end - end - sig { returns(T::Array[T::Hash[T.untyped, T.untyped]]) } def self.rubocop_todo_ymls @rubocop_todo_ymls = T.let(@rubocop_todo_ymls, T.nilable(T::Array[T::Hash[T.untyped, T.untyped]])) diff --git a/lib/package_protections/rubocop_protection_interface.rb b/lib/package_protections/rubocop_protection_interface.rb index e54dbfb..70384f7 100644 --- a/lib/package_protections/rubocop_protection_interface.rb +++ b/lib/package_protections/rubocop_protection_interface.rb @@ -57,9 +57,9 @@ def included_globs_for_pack; end # but a default is provided. ############################################################################ sig do - params(package: ProtectedPackage).returns(T::Hash[T.untyped, T.untyped]) + returns(T::Hash[T.untyped, T.untyped]) end - def custom_cop_config(package) + def custom_cop_config {} end @@ -135,7 +135,8 @@ def cop_configs(packages) CopConfig.new( name: cop_name, enabled: include_paths.any?, - include_paths: include_paths + include_paths: include_paths, + metadata: custom_cop_config ) ] end diff --git a/lib/rubocop/cop/package_protections/only_class_methods.rb b/lib/rubocop/cop/package_protections/only_class_methods.rb index 859a7a3..fc6e93a 100644 --- a/lib/rubocop/cop/package_protections/only_class_methods.rb +++ b/lib/rubocop/cop/package_protections/only_class_methods.rb @@ -33,6 +33,15 @@ def included_globs_for_pack ] end + sig do + override.returns(T::Hash[T.untyped, T.untyped]) + end + def custom_cop_config + { + 'AcceptableParentClasses' => ::PackageProtections.config.acceptable_parent_classes, + } + end + sig { override.returns(String) } def identifier IDENTIFIER diff --git a/spec/package_protections_spec.rb b/spec/package_protections_spec.rb index 7d7f8af..c043abd 100644 --- a/spec/package_protections_spec.rb +++ b/spec/package_protections_spec.rb @@ -1295,7 +1295,18 @@ def get_new_violations it 'generates the expected rubocop.yml entries' do apples_package_yml_with_api_documentation_protection_set_to_fail_never cop_config = get_resulting_rubocop[cop_name] - expect(cop_config).to eq({ 'Enabled' => false }) + expect(cop_config).to eq({ 'Enabled' => false, 'AcceptableParentClasses' => []}) + end + + context 'acceptable parent classes is configured' do + it 'generates the expected rubocop.yml entries' do + PackageProtections.configure do |config| + config.acceptable_parent_classes = ['Blah'] + end + apples_package_yml_with_api_documentation_protection_set_to_fail_never + cop_config = get_resulting_rubocop[cop_name] + expect(cop_config).to eq({ 'Enabled' => false, 'AcceptableParentClasses' => ['Blah']}) + end end it 'is implemented by Rubocop' do