Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

Commit

Permalink
Fix issue with only class methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Evanczuk committed Oct 7, 2022
1 parent a0dfbc2 commit 6b87d0f
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 27 deletions.
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
package_protections (2.5.0)
package_protections (2.5.1)
activesupport
parse_packwerk
rubocop
Expand Down Expand Up @@ -68,7 +68,7 @@ GEM
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.21.0)
parser (>= 3.1.1.0)
rubocop-packs (0.0.9)
rubocop-packs (0.0.10)
activesupport
parse_packwerk
rubocop
Expand Down
9 changes: 0 additions & 9 deletions lib/package_protections.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down
11 changes: 0 additions & 11 deletions lib/package_protections/private.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]]))
Expand Down
7 changes: 4 additions & 3 deletions lib/package_protections/rubocop_protection_interface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions lib/rubocop/cop/package_protections/only_class_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package_protections.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Gem::Specification.new do |spec|
spec.name = 'package_protections'
spec.version = '2.5.0'
spec.version = '2.5.1'
spec.authors = ['Gusto Engineers']
spec.email = ['[email protected]']
spec.summary = 'Package protections for Rails apps'
Expand Down
13 changes: 12 additions & 1 deletion spec/package_protections_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6b87d0f

Please sign in to comment.