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

Remove custom cop_configs on namespace protection #42

Merged
merged 2 commits into from
Nov 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.1.0)
package_protections (3.2.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.14)
rubocop-packs (0.0.15)
activesupport
parse_packwerk
rubocop
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,6 @@ class NamespacedUnderPackageName < Packs::NamespaceConvention
extend T::Sig
include ::PackageProtections::RubocopProtectionInterface

# We override `cop_configs` for this protection.
# The default behavior disables cops when a package has turned off a protection.
# However: namespace violations can occur even when one package has TURNED OFF their namespace protection
# but another package has it turned on. Therefore, all packages must always be opted in no matter what.
#
sig do
params(packages: T::Array[::PackageProtections::ProtectedPackage])
.returns(T::Array[::PackageProtections::RubocopProtectionInterface::CopConfig])
end
def cop_configs(packages)
include_packs = T.let([], T::Array[String])
packages.each do |p|
enabled_for_pack = !p.violation_behavior_for(NamespacedUnderPackageName::IDENTIFIER).fail_never?
if enabled_for_pack
include_packs << p.name
end
end

[
::PackageProtections::RubocopProtectionInterface::CopConfig.new(
name: cop_name,
enabled: include_packs.any?,
metadata: {
'IncludePacks' => include_packs,
'GloballyPermittedNamespaces' => ::RuboCop::Packs.config.globally_permitted_namespaces
}
)
]
end

sig { override.returns(T::Array[String]) }
def included_globs_for_pack
[
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.1.0'
spec.version = '3.2.0'
spec.authors = ['Gusto Engineers']
spec.email = ['[email protected]']
spec.summary = 'Package protections for Rails apps'
Expand Down
18 changes: 5 additions & 13 deletions spec/package_protections_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ def get_new_violations
it 'generates the expected rubocop.yml entries' do
apples_package_yml_with_namespace_protection_set_to_fail_never
cop_config = get_resulting_rubocop['PackageProtections/NamespacedUnderPackageName']
expect(cop_config).to eq({ 'Enabled' => false, 'GloballyPermittedNamespaces' => [], 'IncludePacks' => [] })
expect(cop_config).to eq({ 'Enabled' => false })
end

it 'is implemented by Rubocop' do
Expand Down Expand Up @@ -689,9 +689,7 @@ def get_new_violations
apples_package_yml_with_namespace_protection_set_to_fail_on_new
cop_config = get_resulting_rubocop['PackageProtections/NamespacedUnderPackageName']
expect(cop_config['Exclude']).to eq(nil)
expect(cop_config['Include']).to eq(nil)
expect(cop_config['IncludePacks']).to eq(['packs/apples'])
expect(cop_config['GloballyPermittedNamespaces']).to eq([])
expect(cop_config['Include']).to eq(['packs/apples/app/**/*', 'packs/apples/lib/**/*'])
end
end

Expand All @@ -702,10 +700,8 @@ def get_new_violations
apples_package_yml_with_namespace_protection_set_to_fail_on_new
cop_config = get_resulting_rubocop['PackageProtections/NamespacedUnderPackageName']
expect(cop_config['Exclude']).to eq(nil)
expect(cop_config['Include']).to eq(nil)
expect(cop_config['IncludePacks']).to eq(['packs/apples'])
expect(cop_config['Include']).to eq(['packs/apples/app/**/*', 'packs/apples/lib/**/*'])
expect(cop_config['Enabled']).to eq(true)
expect(cop_config['GloballyPermittedNamespaces']).to eq(%w[AppleTrees Ciders Apples])
end
end

Expand All @@ -728,9 +724,7 @@ def get_new_violations
cop_config = get_resulting_rubocop['PackageProtections/NamespacedUnderPackageName']
expect(cop_config['Exclude']).to eq(nil)
expect(cop_config['Enabled']).to eq(true)
expect(cop_config['Include']).to eq(nil)
expect(cop_config['IncludePacks']).to eq(['packs/apples/subpack'])
expect(cop_config['GloballyPermittedNamespaces']).to eq([])
expect(cop_config['Include']).to eq(['packs/apples/subpack/app/**/*', 'packs/apples/subpack/lib/**/*'])
end
end

Expand All @@ -742,9 +736,7 @@ def get_new_violations
cop_config = get_resulting_rubocop['PackageProtections/NamespacedUnderPackageName']
expect(cop_config['Exclude']).to eq(nil)
expect(cop_config['Enabled']).to eq(true)
expect(cop_config['Include']).to eq(nil)
expect(cop_config['IncludePacks']).to eq(['packs/apples/subpack'])
expect(cop_config['GloballyPermittedNamespaces']).to eq(%w[AppleTrees Ciders Apples])
expect(cop_config['Include']).to eq(['packs/apples/subpack/app/**/*', 'packs/apples/subpack/lib/**/*'])
end
end

Expand Down