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

Commit

Permalink
Bump rubocop-packs to support pack based .rubocop.yml files (#41)
Browse files Browse the repository at this point in the history
* Remove deprecated guard

* Bump rubocop-packs

* Bump pp
  • Loading branch information
Alex Evanczuk authored Nov 1, 2022
1 parent 4d41ce5 commit 8cc0e79
Show file tree
Hide file tree
Showing 6 changed files with 67 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 (3.0.0)
package_protections (3.1.0)
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.13)
rubocop-packs (0.0.14)
activesupport
parse_packwerk
rubocop
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ This protection only looks at files in `packs/your_pack/app` (it ignores spec fi
This protection is implemented via Rubocop -- expect to see results for this when running `rubocop` however you normally do. To add to the TODO list, add to `.rubocop_todo.yml`
Lastly – this protection can be configured by setting `globally_permitted_namespaces`, e.g.:
```ruby
PackageProtections.configure do |config|
RuboCop::Packs.configure do |config|
config.globally_permitted_namespaces = ['SomeGlobalNamespace']
end
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def cop_configs(packages)
enabled: include_packs.any?,
metadata: {
'IncludePacks' => include_packs,
'GloballyPermittedNamespaces' => ::PackageProtections.config.globally_permitted_namespaces
'GloballyPermittedNamespaces' => ::RuboCop::Packs.config.globally_permitted_namespaces
}
)
]
Expand All @@ -57,23 +57,19 @@ def identifier

sig { override.params(behavior: ::PackageProtections::ViolationBehavior, package: ParsePackwerk::Package).returns(T.nilable(String)) }
def unmet_preconditions_for_behavior(behavior, package)
if !behavior.enabled? && !package.metadata['global_namespaces'].nil?
"Invalid configuration for package `#{package.name}`. `#{identifier}` must be turned on to use `global_namespaces` configuration."
else
# We don't need to validate if the behavior is currentely fail_never
return if behavior.fail_never?
# We don't need to validate if the behavior is currentely fail_never
return if behavior.fail_never?

# The reason for this is precondition is the `MultipleNamespacesProtection` assumes this to work properly.
# To remove this precondition, we need to modify `MultipleNamespacesProtection` to be more generalized!
is_root_package = package.name == ParsePackwerk::ROOT_PACKAGE_NAME
in_allowed_directory = ::PackageProtections::EXPECTED_PACK_DIRECTORIES.any? do |expected_package_directory|
package.directory.to_s.start_with?(expected_package_directory)
end
if in_allowed_directory || is_root_package
nil
else
"Package #{package.name} must be located in one of #{::PackageProtections::EXPECTED_PACK_DIRECTORIES.join(', ')} (or be the root) to use this protection"
end
# The reason for this is precondition is the `MultipleNamespacesProtection` assumes this to work properly.
# To remove this precondition, we need to modify `MultipleNamespacesProtection` to be more generalized!
is_root_package = package.name == ParsePackwerk::ROOT_PACKAGE_NAME
in_allowed_directory = ::PackageProtections::EXPECTED_PACK_DIRECTORIES.any? do |expected_package_directory|
package.directory.to_s.start_with?(expected_package_directory)
end
if in_allowed_directory || is_root_package
nil
else
"Package #{package.name} must be located in one of #{::PackageProtections::EXPECTED_PACK_DIRECTORIES.join(', ')} (or be the root) to use this protection"
end
end

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 = '3.0.0'
spec.version = '3.1.0'
spec.authors = ['Gusto Engineers']
spec.email = ['[email protected]']
spec.summary = 'Package protections for Rails apps'
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions spec/package_protections_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
PackageProtections.bust_cache!
allow(Bundler).to receive(:root).and_return(Pathname.new('.'))

PackageProtections.configure do |config|
RuboCop::Packs.configure do |config|
config.globally_permitted_namespaces = globally_permitted_namespaces
end
end
Expand Down Expand Up @@ -1615,7 +1615,7 @@ def get_new_violations
let(:globally_permitted_namespaces) { ['MyNamespace'] }

it 'properly configures package protections' do
expect(PackageProtections.config.globally_permitted_namespaces).to eq(['MyNamespace'])
expect(RuboCop::Packs.config.globally_permitted_namespaces).to eq(['MyNamespace'])
end
end
end
Expand Down

0 comments on commit 8cc0e79

Please sign in to comment.