modularization_statistics 1.42.0 → 1.43.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 79da508fe87219aecb90819b7b1cb7c1681108e8938fc48079d2dac98de6b998
4
- data.tar.gz: 408f7f9f5bef70a3e11f8022cd7c6a328ad744095625aa94fc1af4757177c903
3
+ metadata.gz: f62a7a832093f586bea43e63af693a848f52cf0e4528348746424d4a80c10d12
4
+ data.tar.gz: a7d15eff1dc8014fd5552372081d6a171dff2625dade956b6ef0554e45631c3f
5
5
  SHA512:
6
- metadata.gz: fdd4ec7596f32e10267deb3bb1a75c3a84e4269b583317a9879ce7e992caaf2503daf20b64c27f1471395e51f0d575d3ef6aa1bf424ce53af3f71b75f7a6df7d
7
- data.tar.gz: ec1c565bf1c3a5e01fea05a8fa128ac35519adbb58939ef787dca80b2c6db1e5054f6407ef619cde00efacaa5395827aac8c8b4f5690efb8e518e6d0888f7340
6
+ metadata.gz: 2b510bef418709597c3c215d24752de7db71f411765517c350cfc4e8ebf5e396ecb7399ab340defbdc8bb6538e38cdb713f2d209407c5ced0ed4ff0a17f9b04a
7
+ data.tar.gz: 3dc87181542fcb8bcb37561d9aa12df9ebe152f397da7c5f01c3b5b579c048102e9640929d1d6e6d3d806d6bbf5386524b411d2679324bf483e335d8b8065730
@@ -5,8 +5,8 @@ require 'dogapi'
5
5
  require 'modularization_statistics/private/metrics'
6
6
  require 'modularization_statistics/private/metrics/files'
7
7
  require 'modularization_statistics/private/metrics/public_usage'
8
- require 'modularization_statistics/private/metrics/protection_usage'
9
- require 'modularization_statistics/private/metrics/rubocop_protections_exclusions'
8
+ require 'modularization_statistics/private/metrics/packwerk_checker_usage'
9
+ require 'modularization_statistics/private/metrics/rubocop_usage'
10
10
  require 'modularization_statistics/private/metrics/packages'
11
11
  require 'modularization_statistics/private/metrics/packages_by_team'
12
12
  require 'modularization_statistics/private/metrics/nested_packs'
@@ -32,8 +32,8 @@ module ModularizationStatistics
32
32
  all_metrics += Metrics::PublicUsage.get_public_usage_metrics('all_packages', packages, package_tags)
33
33
  all_metrics << GaugeMetric.for('all_packages.has_readme.count', packages.count { |package| Metrics.has_readme?(package) }, package_tags)
34
34
 
35
- all_metrics += Metrics::ProtectionUsage.get_protections_metrics('all_packages', packages, package_tags)
36
- all_metrics += Metrics::RubocopProtectionsExclusions.get_rubocop_exclusions('all_packages', packages, package_tags)
35
+ all_metrics += Metrics::PackwerkCheckerUsage.get_checker_metrics('all_packages', packages, package_tags)
36
+ all_metrics += Metrics::RubocopUsage.get_metrics('all_packages', packages, package_tags)
37
37
  all_metrics << GaugeMetric.for('all_packages.package_based_file_ownership.count', packages.count { |package| !package.metadata['owner'].nil? }, package_tags)
38
38
 
39
39
  inbound_violations_by_package = packages.flat_map(&:violations).group_by(&:to_package_name)
@@ -23,7 +23,7 @@ module ModularizationStatistics
23
23
 
24
24
  team_tags = Metrics.tags_for_team(team_name) + [app_level_tag]
25
25
  all_metrics << GaugeMetric.for('by_team.all_packages.count', packages_by_team.count, team_tags)
26
- all_metrics += Metrics::ProtectionUsage.get_protections_metrics('by_team', packages_by_team, team_tags)
26
+ all_metrics += Metrics::PackwerkCheckerUsage.get_checker_metrics('by_team', packages_by_team, team_tags)
27
27
  all_metrics += Metrics::PublicUsage.get_public_usage_metrics('by_team', packages_by_team, team_tags)
28
28
 
29
29
  all_metrics << GaugeMetric.for('by_team.notify_on_package_yml_changes.count', packages_by_team.count { |p| p.metadata['notify_on_package_yml_changes'] }, team_tags)
@@ -0,0 +1,57 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require 'rubocop-packs'
5
+
6
+ module ModularizationStatistics
7
+ module Private
8
+ module Metrics
9
+ class PackwerkCheckerUsage
10
+ extend T::Sig
11
+
12
+ # Later, we might find a way we can get this directly from `packwerk`
13
+ class PackwerkChecker < T::Struct
14
+ const :setting, String
15
+ const :strict_mode, String
16
+ # Later, we might convert to legacy metric names later so new clients get more sensible metric names
17
+ # That is, we might want to see metrics that are more closely connected to the new API.
18
+ # e.g. instead of `all_packages.prevent_this_package_from_violating_its_stated_dependencies.fail_on_any.count`, we'd see `all_packages.checkers.enforce_dependencies.strict.count`
19
+ # e.g. instead of `all_packages.prevent_this_package_from_creating_other_namespaces.fail_on_new.count`, `all_packages.cops.packs_namespaceconvention.true.count`
20
+ const :legacy_metric_name, String
21
+ end
22
+
23
+ sig { params(prefix: String, packages: T::Array[ParsePackwerk::Package], package_tags: T::Array[Tag]).returns(T::Array[GaugeMetric]) }
24
+ def self.get_checker_metrics(prefix, packages, package_tags)
25
+ metrics = T.let([], T::Array[GaugeMetric])
26
+
27
+ checkers = [
28
+ PackwerkChecker.new(setting: 'enforce_dependencies', strict_mode: 'enforce_dependencies_strictly', legacy_metric_name: 'prevent_this_package_from_violating_its_stated_dependencies'),
29
+ PackwerkChecker.new(setting: 'enforce_privacy', strict_mode: 'enforce_privacy_strictly', legacy_metric_name: 'prevent_other_packages_from_using_this_packages_internals')
30
+ ]
31
+
32
+ checkers.each do |checker|
33
+ ['no', 'fail_the_build_if_new_instances_appear', 'fail_the_build_on_any_instances'].each do |violation_behavior|
34
+ count_of_packages = ParsePackwerk.all.count do |package|
35
+ strict_mode = package.metadata[checker.strict_mode]
36
+ enabled = YAML.load_file(package.yml)[checker.setting]
37
+ case violation_behavior
38
+ when 'fail_the_build_on_any_instances'
39
+ !!strict_mode
40
+ when 'no'
41
+ !enabled
42
+ when 'fail_the_build_if_new_instances_appear'
43
+ enabled && !strict_mode
44
+ end
45
+ end
46
+
47
+ metric_name = "#{prefix}.#{checker.legacy_metric_name}.#{violation_behavior}.count"
48
+ metrics << GaugeMetric.for(metric_name, count_of_packages, package_tags)
49
+ end
50
+ end
51
+
52
+ metrics
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,94 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module ModularizationStatistics
5
+ module Private
6
+ module Metrics
7
+ class RubocopUsage
8
+ extend T::Sig
9
+
10
+ sig { params(prefix: String, packages: T::Array[ParsePackwerk::Package], package_tags: T::Array[Tag]).returns(T::Array[GaugeMetric]) }
11
+ def self.get_metrics(prefix, packages, package_tags)
12
+ [
13
+ *get_rubocop_exclusions(prefix, packages, package_tags),
14
+ *get_rubocop_usage_metrics(prefix, packages, package_tags)
15
+ ]
16
+ end
17
+
18
+ sig { params(prefix: String, packages: T::Array[ParsePackwerk::Package], package_tags: T::Array[Tag]).returns(T::Array[GaugeMetric]) }
19
+ def self.get_rubocop_usage_metrics(prefix, packages, package_tags)
20
+ # Rubocops
21
+ metrics = T.let([], T::Array[GaugeMetric])
22
+
23
+ rubocop_legacy_metric_map.each do |cop_name, legacy_name|
24
+ ['no', 'fail_the_build_if_new_instances_appear', 'fail_the_build_on_any_instances'].each do |violation_behavior|
25
+ count_of_packages = ParsePackwerk.all.count do |package|
26
+ # We will likely want a rubocop-packs API for this, to be able to ask if a cop is enabled for a pack.
27
+ # It's possible we will want to allow these to be enabled at the top-level `.rubocop.yml`,
28
+ # in which case we wouldn't get the right metrics with this approach. However, we can also accept
29
+ # that as a current limitation.
30
+ rubocop_yml_file = package.directory.join(RuboCop::Packs::PACK_LEVEL_RUBOCOP_YML)
31
+ next false if !rubocop_yml_file.exist?
32
+ rubocop_yml = YAML.load_file(rubocop_yml_file)
33
+ cop_config = rubocop_yml[cop_name]
34
+
35
+ strict_mode = cop_config && cop_config['FailureMode'] == 'strict'
36
+ enabled = cop_config && cop_config['Enabled']
37
+ case violation_behavior
38
+ when 'fail_the_build_on_any_instances'
39
+ !!strict_mode
40
+ when 'no'
41
+ !enabled
42
+ when 'fail_the_build_if_new_instances_appear'
43
+ enabled && !strict_mode
44
+ end
45
+ end
46
+
47
+ metric_name = "#{prefix}.#{legacy_name}.#{violation_behavior}.count"
48
+ metrics << GaugeMetric.for(metric_name, count_of_packages, package_tags)
49
+ end
50
+ end
51
+
52
+ metrics
53
+ end
54
+
55
+ sig { params(prefix: String, packages: T::Array[ParsePackwerk::Package], package_tags: T::Array[Tag]).returns(T::Array[GaugeMetric]) }
56
+ def self.get_rubocop_exclusions(prefix, packages, package_tags)
57
+ rubocop_legacy_metric_map.flat_map do |cop_name, legacy_name|
58
+ metric_name = "#{prefix}.#{legacy_name}.rubocop_exclusions.count"
59
+ all_exclusions_count = ParsePackwerk.all.sum { |package| exclude_count_for_package_and_protection(package, cop_name)}
60
+ GaugeMetric.for(metric_name, all_exclusions_count, package_tags)
61
+ end
62
+ end
63
+
64
+ # TODO: `rubocop-packs` may want to expose API for this
65
+ sig { params(package: ParsePackwerk::Package, cop_name: String).returns(Integer) }
66
+ def self.exclude_count_for_package_and_protection(package, cop_name)
67
+ if package.name == ParsePackwerk::ROOT_PACKAGE_NAME
68
+ rubocop_todo = package.directory.join('.rubocop_todo.yml')
69
+ else
70
+ rubocop_todo = package.directory.join(RuboCop::Packs::PACK_LEVEL_RUBOCOP_TODO_YML)
71
+ end
72
+
73
+ if rubocop_todo.exist?
74
+ loaded_rubocop_todo = YAML.load_file(rubocop_todo)
75
+ cop_config = loaded_rubocop_todo.fetch(cop_name, {})
76
+ cop_config.fetch('Exclude', []).count
77
+ else
78
+ 0
79
+ end
80
+ end
81
+
82
+ sig { returns(T::Hash[String, String])}
83
+ def self.rubocop_legacy_metric_map
84
+ {
85
+ 'Packs/ClassMethodsAsPublicApis' => 'prevent_this_package_from_exposing_an_untyped_api',
86
+ 'Packs/RootNamespaceIsPackName' => 'prevent_this_package_from_creating_other_namespaces',
87
+ 'Packs/TypedPublicApis' => 'prevent_this_package_from_exposing_an_untyped_api',
88
+ 'Packs/DocumentedPublicApis' => 'prevent_this_package_from_exposing_undocumented_public_apis',
89
+ }
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
@@ -10,7 +10,6 @@ require 'pathname'
10
10
  require 'modularization_statistics/private/source_code_file'
11
11
  require 'modularization_statistics/private/datadog_reporter'
12
12
  require 'parse_packwerk'
13
- require 'package_protections'
14
13
  require 'modularization_statistics/tag'
15
14
  require 'modularization_statistics/tags'
16
15
  require 'modularization_statistics/gauge_metric'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: modularization_statistics
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.42.0
4
+ version: 1.43.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gusto Engineers
@@ -53,7 +53,7 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: package_protections
56
+ name: parse_packwerk
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
@@ -67,7 +67,7 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: parse_packwerk
70
+ name: sorbet-runtime
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="
@@ -81,7 +81,7 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: sorbet-runtime
84
+ name: rubocop-packs
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - ">="
@@ -182,9 +182,9 @@ files:
182
182
  - lib/modularization_statistics/private/metrics/nested_packs.rb
183
183
  - lib/modularization_statistics/private/metrics/packages.rb
184
184
  - lib/modularization_statistics/private/metrics/packages_by_team.rb
185
- - lib/modularization_statistics/private/metrics/protection_usage.rb
185
+ - lib/modularization_statistics/private/metrics/packwerk_checker_usage.rb
186
186
  - lib/modularization_statistics/private/metrics/public_usage.rb
187
- - lib/modularization_statistics/private/metrics/rubocop_protections_exclusions.rb
187
+ - lib/modularization_statistics/private/metrics/rubocop_usage.rb
188
188
  - lib/modularization_statistics/private/source_code_file.rb
189
189
  - lib/modularization_statistics/tag.rb
190
190
  - lib/modularization_statistics/tags.rb
@@ -193,7 +193,6 @@ files:
193
193
  - sorbet/rbi/gems/code_teams@1.0.0.rbi
194
194
  - sorbet/rbi/gems/dogapi@1.45.0.rbi
195
195
  - sorbet/rbi/gems/manual.rbi
196
- - sorbet/rbi/gems/package_protections@4.0.1.rbi
197
196
  - sorbet/rbi/gems/parse_packwerk@0.14.0.rbi
198
197
  - sorbet/rbi/gems/rspec@3.10.0.rbi
199
198
  - sorbet/rbi/gems/rubocop-packs@0.0.20.rbi
@@ -1,134 +0,0 @@
1
- # typed: strict
2
- # frozen_string_literal: true
3
-
4
- module ModularizationStatistics
5
- module Private
6
- module Metrics
7
- class ProtectionUsage
8
- extend T::Sig
9
-
10
- sig { params(prefix: String, packages: T::Array[ParsePackwerk::Package], package_tags: T::Array[Tag]).returns(T::Array[GaugeMetric]) }
11
- def self.get_protections_metrics(prefix, packages, package_tags)
12
- protected_packages = packages.map { |p| PackageProtections::ProtectedPackage.from(p) }
13
- PackageProtections.all.flat_map do |protection|
14
- PackageProtections::ViolationBehavior.each_value.map do |violation_behavior|
15
- # https://github.com/Gusto/package_protections/pull/42 changed the public API of these violation behaviors.
16
- # To preserve our ability to understand historical trends, we map to the old values.
17
- # This allows our dashboards to continue to operate as expected.
18
- # Note if we ever open source mod stats, we should probably inject this behavior so that new clients can see the new keys in their metrics.
19
- violation_behavior_map = {
20
- PackageProtections::ViolationBehavior::FailOnAny => 'fail_the_build_on_any_instances',
21
- PackageProtections::ViolationBehavior::FailNever => 'no',
22
- PackageProtections::ViolationBehavior::FailOnNew => 'fail_the_build_if_new_instances_appear',
23
- }
24
- violation_behavior_name = violation_behavior_map[violation_behavior]
25
- metric_name = "#{prefix}.#{protection.identifier}.#{violation_behavior_name}.count"
26
- count_of_packages = protected_packages.count do |p|
27
- #
28
- # This is temporarily in place until we migrate off of `package_protections` in favor of `rubocop-packs`.
29
- # At that point, we want to delete this branch and instead it we'd probably have two separate branches.
30
- # One branch would look at `enforce_x` and `metadata.enforce_x_strictly`.
31
- # The other branch would look at `.pack_rubocop.yml`.
32
- # Later on, we could generalize this so that it automatically incorporates new cops from `rubocop-packs`,
33
- # or even new packwerk plugins.
34
- #
35
- # Regardless, we'll want to keep the way we are naming these behaviors for now to preserve historical trends in the data.
36
- #
37
- if p.metadata['protections']
38
- p.violation_behavior_for(protection.identifier) == violation_behavior
39
- else
40
- should_count_package?(p.original_package, protection, violation_behavior)
41
- end
42
- end
43
- GaugeMetric.for(metric_name, count_of_packages, package_tags)
44
- end
45
- end
46
- end
47
-
48
- #
49
- # Later, when we remove package protections, we can make this simpler by iterating over
50
- # packwerk checkers and rubocop packs specifically. That would let us use a common, simple
51
- # strategy to get metrics for both of them. For the first iteration, we'll want to continue
52
- # to map the old names of things to the "protection" names. After that, I think we will want to
53
- # extract that mapping into a tool that transforms the metrics that can be optionally turned off
54
- # so that we can see metrics that are more closely connected to the new API.
55
- # e.g. instead of `all_packages.prevent_this_package_from_violating_its_stated_dependencies.fail_on_any.count`, we'd see
56
- # e.g. instead of `all_packages.checkers.enforce_dependencies.strict.count`, we'd see
57
- # e.g. instead of `all_packages.prevent_this_package_from_creating_other_namespaces.fail_on_new.count`, we'd see
58
- # e.g. instead of `all_packages.cops.packs_namespaceconvention.true.count`, we'd see
59
- #
60
- sig do
61
- params(
62
- package: ParsePackwerk::Package,
63
- protection: PackageProtections::ProtectionInterface,
64
- violation_behavior: PackageProtections::ViolationBehavior
65
- ).returns(T::Boolean)
66
- end
67
- def self.should_count_package?(package, protection, violation_behavior)
68
- if protection.identifier == 'prevent_this_package_from_violating_its_stated_dependencies'
69
- strict_mode = package.metadata['enforce_dependencies_strictly']
70
- enabled = package.enforces_dependencies?
71
-
72
- case violation_behavior
73
- when PackageProtections::ViolationBehavior::FailOnAny
74
- !!strict_mode
75
- when PackageProtections::ViolationBehavior::FailNever
76
- !enabled
77
- when PackageProtections::ViolationBehavior::FailOnNew
78
- enabled && !strict_mode
79
- else
80
- T.absurd(violation_behavior)
81
- end
82
- elsif protection.identifier == 'prevent_other_packages_from_using_this_packages_internals'
83
- strict_mode = package.metadata['enforce_privacy_strictly']
84
- enabled = package.enforces_privacy?
85
-
86
- case violation_behavior
87
- when PackageProtections::ViolationBehavior::FailOnAny
88
- !!strict_mode
89
- when PackageProtections::ViolationBehavior::FailNever
90
- !enabled
91
- when PackageProtections::ViolationBehavior::FailOnNew
92
- enabled && !strict_mode
93
- else
94
- T.absurd(violation_behavior)
95
- end
96
- else
97
- # Otherwise, we're in a rubocop case
98
- rubocop_yml_file = package.directory.join(RuboCop::Packs::PACK_LEVEL_RUBOCOP_YML)
99
- return false if !rubocop_yml_file.exist?
100
- rubocop_yml = YAML.load_file(rubocop_yml_file)
101
- protection = T.cast(protection, PackageProtections::RubocopProtectionInterface)
102
- # We will likely want a rubocop-packs API for this, to be able to ask if a cop is enabled for a pack.
103
- # It's possible we will want to allow these to be enabled at the top-level `.rubocop.yml`,
104
- # in which case we wouldn't get the right metrics with this approach. However, we can also accept
105
- # that as a current limitation.
106
- cop_map = {
107
- 'PackageProtections/TypedPublicApi' => 'Packs/TypedPublicApis',
108
- 'PackageProtections/NamespacedUnderPackageName' => 'Packs/RootNamespaceIsPackName',
109
- 'PackageProtections/OnlyClassMethods' => 'Packs/ClassMethodsAsPublicApis',
110
- 'PackageProtections/RequireDocumentedPublicApis' => 'Packs/DocumentedPublicApis',
111
- }
112
- # We want to use the cop names from `rubocop-packs`. Eventually, we'll just literate over these
113
- # cop names directly, or ask `rubocop-packs` for the list of cops to care about.
114
- cop_config = rubocop_yml[cop_map[protection.cop_name]]
115
- return false if cop_config.nil?
116
- enabled = cop_config['Enabled']
117
- strict_mode = cop_config['FailureMode'] == 'strict'
118
-
119
- case violation_behavior
120
- when PackageProtections::ViolationBehavior::FailOnAny
121
- !!strict_mode
122
- when PackageProtections::ViolationBehavior::FailNever
123
- !enabled
124
- when PackageProtections::ViolationBehavior::FailOnNew
125
- enabled && !strict_mode
126
- else
127
- T.absurd(violation_behavior)
128
- end
129
- end
130
- end
131
- end
132
- end
133
- end
134
- end
@@ -1,42 +0,0 @@
1
- # typed: strict
2
- # frozen_string_literal: true
3
-
4
- module ModularizationStatistics
5
- module Private
6
- module Metrics
7
- class RubocopProtectionsExclusions
8
- extend T::Sig
9
-
10
- sig { params(prefix: String, packages: T::Array[ParsePackwerk::Package], package_tags: T::Array[Tag]).returns(T::Array[GaugeMetric]) }
11
- def self.get_rubocop_exclusions(prefix, packages, package_tags)
12
- protected_packages = packages.map { |p| PackageProtections::ProtectedPackage.from(p) }
13
-
14
- rubocop_based_package_protections = T.cast(PackageProtections.all.select { |p| p.is_a?(PackageProtections::RubocopProtectionInterface) }, T::Array[PackageProtections::RubocopProtectionInterface])
15
- rubocop_based_package_protections.flat_map do |rubocop_based_package_protection|
16
- metric_name = "#{prefix}.#{rubocop_based_package_protection.identifier}.rubocop_exclusions.count"
17
- all_exclusions_count = ParsePackwerk.all.sum { |package| exclude_count_for_package_and_protection(package, rubocop_based_package_protection)}
18
- GaugeMetric.for(metric_name, all_exclusions_count, package_tags)
19
- end
20
- end
21
-
22
- # TODO: `rubocop-packs` may want to expose API for this
23
- sig { params(package: ParsePackwerk::Package, protection: PackageProtections::RubocopProtectionInterface).returns(Integer) }
24
- def self.exclude_count_for_package_and_protection(package, protection)
25
- if package.name == ParsePackwerk::ROOT_PACKAGE_NAME
26
- rubocop_todo = package.directory.join('.rubocop_todo.yml')
27
- else
28
- rubocop_todo = package.directory.join(RuboCop::Packs::PACK_LEVEL_RUBOCOP_TODO_YML)
29
- end
30
-
31
- if rubocop_todo.exist?
32
- loaded_rubocop_todo = YAML.load_file(rubocop_todo)
33
- cop_config = loaded_rubocop_todo.fetch(protection.cop_name, {})
34
- cop_config.fetch('Exclude', []).count
35
- else
36
- 0
37
- end
38
- end
39
- end
40
- end
41
- end
42
- end
@@ -1,526 +0,0 @@
1
- # typed: true
2
-
3
- # DO NOT EDIT MANUALLY
4
- # This is an autogenerated file for types exported from the `package_protections` gem.
5
- # Please instead update this file by running `bin/tapioca gem package_protections`.
6
-
7
- module PackageProtections
8
- class << self
9
- sig { returns(T::Array[::PackageProtections::ProtectionInterface]) }
10
- def all; end
11
-
12
- sig { void }
13
- def bust_cache!; end
14
-
15
- sig { returns(::PackageProtections::Private::Configuration) }
16
- def config; end
17
-
18
- sig { params(blk: T.proc.params(arg0: ::PackageProtections::Private::Configuration).void).void }
19
- def configure(&blk); end
20
-
21
- sig do
22
- params(
23
- packages: T::Array[::ParsePackwerk::Package],
24
- new_violations: T::Array[::PackageProtections::PerFileViolation]
25
- ).returns(T::Array[::PackageProtections::Offense])
26
- end
27
- def get_offenses(packages:, new_violations:); end
28
-
29
- sig { params(root_pathname: ::Pathname).returns(::String) }
30
- def rubocop_yml(root_pathname: T.unsafe(nil)); end
31
-
32
- sig do
33
- params(
34
- packages: T::Array[::ParsePackwerk::Package],
35
- protection_identifiers: T::Array[::String],
36
- verbose: T::Boolean
37
- ).void
38
- end
39
- def set_defaults!(packages, protection_identifiers: T.unsafe(nil), verbose: T.unsafe(nil)); end
40
-
41
- sig { returns(T::Array[::String]) }
42
- def validate!; end
43
-
44
- sig { params(identifier: ::String).returns(::PackageProtections::ProtectionInterface) }
45
- def with_identifier(identifier); end
46
- end
47
- end
48
-
49
- PackageProtections::EXPECTED_PACK_DIRECTORIES = T.let(T.unsafe(nil), Array)
50
- PackageProtections::Identifier = T.type_alias { ::String }
51
- class PackageProtections::IncorrectPublicApiUsageError < ::StandardError; end
52
-
53
- class PackageProtections::Offense < ::T::Struct
54
- const :file, ::String
55
- const :message, ::String
56
- const :package, ::ParsePackwerk::Package
57
- const :violation_type, ::String
58
-
59
- sig { returns(::String) }
60
- def package_name; end
61
-
62
- class << self
63
- def inherited(s); end
64
- end
65
- end
66
-
67
- PackageProtections::PROTECTIONS_TODO_YML = T.let(T.unsafe(nil), String)
68
-
69
- class PackageProtections::PerFileViolation < ::T::Struct
70
- const :class_name, ::String
71
- const :constant_source_package, ::String
72
- const :filepath, ::String
73
- const :reference_source_package, ::ParsePackwerk::Package
74
- const :type, ::String
75
-
76
- sig { returns(T::Boolean) }
77
- def dependency?; end
78
-
79
- sig { returns(T::Boolean) }
80
- def privacy?; end
81
-
82
- class << self
83
- sig do
84
- params(
85
- violation: ::ParsePackwerk::Violation,
86
- reference_source_package: ::ParsePackwerk::Package
87
- ).returns(T::Array[::PackageProtections::PerFileViolation])
88
- end
89
- def from(violation, reference_source_package); end
90
-
91
- def inherited(s); end
92
- end
93
- end
94
-
95
- module PackageProtections::Private
96
- class << self
97
- sig { returns(T::Array[::PackageProtections::ProtectedPackage]) }
98
- def all_protected_packages; end
99
-
100
- sig { void }
101
- def bust_cache!; end
102
-
103
- sig do
104
- params(
105
- packages: T::Array[::ParsePackwerk::Package],
106
- new_violations: T::Array[::PackageProtections::PerFileViolation]
107
- ).returns(T::Array[::PackageProtections::Offense])
108
- end
109
- def get_offenses(packages:, new_violations:); end
110
-
111
- sig { params(name: ::String).returns(::PackageProtections::ProtectedPackage) }
112
- def get_package_with_name(name); end
113
-
114
- sig { void }
115
- def load_client_configuration; end
116
-
117
- sig { params(root_pathname: ::Pathname).returns(::String) }
118
- def rubocop_yml(root_pathname:); end
119
-
120
- sig do
121
- params(
122
- packages: T::Array[::ParsePackwerk::Package],
123
- protection_identifiers: T::Array[::String],
124
- verbose: T::Boolean
125
- ).void
126
- end
127
- def set_defaults!(packages, protection_identifiers:, verbose:); end
128
- end
129
- end
130
-
131
- class PackageProtections::Private::ColorizedString
132
- sig { params(original_string: ::String, color: ::PackageProtections::Private::ColorizedString::Color).void }
133
- def initialize(original_string, color = T.unsafe(nil)); end
134
-
135
- sig { returns(::PackageProtections::Private::ColorizedString) }
136
- def blue; end
137
-
138
- sig { returns(::String) }
139
- def colorized_to_s; end
140
-
141
- sig { returns(::PackageProtections::Private::ColorizedString) }
142
- def green; end
143
-
144
- sig { returns(::PackageProtections::Private::ColorizedString) }
145
- def light_blue; end
146
-
147
- sig { returns(::PackageProtections::Private::ColorizedString) }
148
- def pink; end
149
-
150
- sig { returns(::PackageProtections::Private::ColorizedString) }
151
- def red; end
152
-
153
- sig { returns(::String) }
154
- def to_s; end
155
-
156
- sig { returns(::PackageProtections::Private::ColorizedString) }
157
- def white; end
158
-
159
- sig { returns(::PackageProtections::Private::ColorizedString) }
160
- def yellow; end
161
-
162
- private
163
-
164
- sig { returns(::Integer) }
165
- def color_code; end
166
-
167
- sig do
168
- params(
169
- color: ::PackageProtections::Private::ColorizedString::Color
170
- ).returns(::PackageProtections::Private::ColorizedString)
171
- end
172
- def colorize(color); end
173
- end
174
-
175
- class PackageProtections::Private::ColorizedString::Color < ::T::Enum
176
- enums do
177
- Black = new
178
- Red = new
179
- Green = new
180
- Yellow = new
181
- Blue = new
182
- Pink = new
183
- LightBlue = new
184
- White = new
185
- end
186
- end
187
-
188
- class PackageProtections::Private::Configuration
189
- sig { void }
190
- def initialize; end
191
-
192
- sig { returns(T::Array[::String]) }
193
- def acceptable_parent_classes; end
194
-
195
- def acceptable_parent_classes=(_arg0); end
196
-
197
- sig { void }
198
- def bust_cache!; end
199
-
200
- sig { returns(T::Array[::PackageProtections::ProtectionInterface]) }
201
- def default_protections; end
202
-
203
- sig { returns(T::Array[::String]) }
204
- def globally_permitted_namespaces; end
205
-
206
- def globally_permitted_namespaces=(_arg0); end
207
-
208
- sig { returns(T::Array[::PackageProtections::ProtectionInterface]) }
209
- def protections; end
210
-
211
- def protections=(_arg0); end
212
- end
213
-
214
- class PackageProtections::Private::IncomingPrivacyProtection
215
- include ::PackageProtections::ProtectionInterface
216
-
217
- sig do
218
- override
219
- .params(
220
- protected_packages: T::Array[::PackageProtections::ProtectedPackage]
221
- ).returns(T::Array[::PackageProtections::Offense])
222
- end
223
- def get_offenses_for_existing_violations(protected_packages); end
224
-
225
- sig do
226
- override
227
- .params(
228
- new_violations: T::Array[::PackageProtections::PerFileViolation]
229
- ).returns(T::Array[::PackageProtections::Offense])
230
- end
231
- def get_offenses_for_new_violations(new_violations); end
232
-
233
- sig { override.returns(::String) }
234
- def humanized_protection_description; end
235
-
236
- sig { override.returns(::String) }
237
- def humanized_protection_name; end
238
-
239
- sig { override.returns(::String) }
240
- def identifier; end
241
-
242
- sig do
243
- override
244
- .params(
245
- behavior: ::PackageProtections::ViolationBehavior,
246
- package: ::ParsePackwerk::Package
247
- ).returns(T.nilable(::String))
248
- end
249
- def unmet_preconditions_for_behavior(behavior, package); end
250
-
251
- private
252
-
253
- sig { params(per_file_violation: ::PackageProtections::PerFileViolation).returns(::String) }
254
- def message_for_fail_on_any(per_file_violation); end
255
-
256
- sig { params(per_file_violation: ::PackageProtections::PerFileViolation).returns(::String) }
257
- def message_for_fail_on_new(per_file_violation); end
258
- end
259
-
260
- PackageProtections::Private::IncomingPrivacyProtection::IDENTIFIER = T.let(T.unsafe(nil), String)
261
-
262
- class PackageProtections::Private::MetadataModifiers
263
- class << self
264
- sig do
265
- params(
266
- package: ::ParsePackwerk::Package,
267
- protection_identifier: ::String,
268
- violation_behavior: ::PackageProtections::ViolationBehavior
269
- ).returns(::ParsePackwerk::Package)
270
- end
271
- def package_with_modified_protection(package, protection_identifier, violation_behavior); end
272
- end
273
- end
274
-
275
- class PackageProtections::Private::OutgoingDependencyProtection
276
- include ::PackageProtections::ProtectionInterface
277
-
278
- sig do
279
- override
280
- .params(
281
- protected_packages: T::Array[::PackageProtections::ProtectedPackage]
282
- ).returns(T::Array[::PackageProtections::Offense])
283
- end
284
- def get_offenses_for_existing_violations(protected_packages); end
285
-
286
- sig do
287
- override
288
- .params(
289
- new_violations: T::Array[::PackageProtections::PerFileViolation]
290
- ).returns(T::Array[::PackageProtections::Offense])
291
- end
292
- def get_offenses_for_new_violations(new_violations); end
293
-
294
- sig { override.returns(::String) }
295
- def humanized_protection_description; end
296
-
297
- sig { override.returns(::String) }
298
- def humanized_protection_name; end
299
-
300
- sig { override.returns(::String) }
301
- def identifier; end
302
-
303
- sig do
304
- override
305
- .params(
306
- behavior: ::PackageProtections::ViolationBehavior,
307
- package: ::ParsePackwerk::Package
308
- ).returns(T.nilable(::String))
309
- end
310
- def unmet_preconditions_for_behavior(behavior, package); end
311
-
312
- private
313
-
314
- sig { params(per_file_violation: ::PackageProtections::PerFileViolation).returns(::String) }
315
- def message_for_fail_on_any(per_file_violation); end
316
-
317
- sig { params(per_file_violation: ::PackageProtections::PerFileViolation).returns(::String) }
318
- def message_for_fail_on_new(per_file_violation); end
319
- end
320
-
321
- PackageProtections::Private::OutgoingDependencyProtection::IDENTIFIER = T.let(T.unsafe(nil), String)
322
-
323
- class PackageProtections::Private::Output
324
- class << self
325
- sig { params(str: ::String).void }
326
- def p(str); end
327
-
328
- sig { params(str: ::PackageProtections::Private::ColorizedString, colorized: T::Boolean).void }
329
- def p_colorized(str, colorized:); end
330
- end
331
- end
332
-
333
- class PackageProtections::ProtectedPackage < ::T::Struct
334
- const :deprecated_references, ::ParsePackwerk::DeprecatedReferences
335
- const :original_package, ::ParsePackwerk::Package
336
- const :protections, T::Hash[::String, ::PackageProtections::ViolationBehavior]
337
-
338
- sig { returns(T::Array[::String]) }
339
- def dependencies; end
340
-
341
- sig { returns(T::Hash[T.untyped, T.untyped]) }
342
- def metadata; end
343
-
344
- sig { returns(::String) }
345
- def name; end
346
-
347
- sig { params(key: ::String).returns(::PackageProtections::ViolationBehavior) }
348
- def violation_behavior_for(key); end
349
-
350
- sig { returns(T::Array[::ParsePackwerk::Violation]) }
351
- def violations; end
352
-
353
- sig { returns(::Pathname) }
354
- def yml; end
355
-
356
- class << self
357
- sig { params(original_package: ::ParsePackwerk::Package).returns(::PackageProtections::ProtectedPackage) }
358
- def from(original_package); end
359
-
360
- sig do
361
- params(
362
- protection: ::PackageProtections::ProtectionInterface,
363
- metadata: T::Hash[T.untyped, T.untyped],
364
- package: ::ParsePackwerk::Package
365
- ).returns(::PackageProtections::ViolationBehavior)
366
- end
367
- def get_violation_behavior(protection, metadata, package); end
368
-
369
- def inherited(s); end
370
- end
371
- end
372
-
373
- module PackageProtections::ProtectionInterface
374
- requires_ancestor { Kernel }
375
-
376
- abstract!
377
-
378
- sig { returns(::PackageProtections::ViolationBehavior) }
379
- def default_behavior; end
380
-
381
- sig do
382
- params(
383
- protected_packages: T::Array[::PackageProtections::ProtectedPackage],
384
- new_violations: T::Array[::PackageProtections::PerFileViolation]
385
- ).returns(T::Array[::PackageProtections::Offense])
386
- end
387
- def get_offenses(protected_packages, new_violations); end
388
-
389
- sig do
390
- abstract
391
- .params(
392
- protected_packages: T::Array[::PackageProtections::ProtectedPackage]
393
- ).returns(T::Array[::PackageProtections::Offense])
394
- end
395
- def get_offenses_for_existing_violations(protected_packages); end
396
-
397
- sig do
398
- abstract
399
- .params(
400
- new_violations: T::Array[::PackageProtections::PerFileViolation]
401
- ).returns(T::Array[::PackageProtections::Offense])
402
- end
403
- def get_offenses_for_new_violations(new_violations); end
404
-
405
- sig { abstract.returns(::String) }
406
- def humanized_protection_description; end
407
-
408
- sig { abstract.returns(::String) }
409
- def humanized_protection_name; end
410
-
411
- sig { abstract.returns(::String) }
412
- def identifier; end
413
-
414
- sig do
415
- params(
416
- behavior: ::PackageProtections::ViolationBehavior,
417
- package: ::ParsePackwerk::Package
418
- ).returns(T::Boolean)
419
- end
420
- def supports_violation_behavior?(behavior, package); end
421
-
422
- sig do
423
- abstract
424
- .params(
425
- behavior: ::PackageProtections::ViolationBehavior,
426
- package: ::ParsePackwerk::Package
427
- ).returns(T.nilable(::String))
428
- end
429
- def unmet_preconditions_for_behavior(behavior, package); end
430
- end
431
-
432
- module PackageProtections::RubocopProtectionInterface
433
- include ::PackageProtections::ProtectionInterface
434
-
435
- abstract!
436
-
437
- sig do
438
- params(
439
- packages: T::Array[::PackageProtections::ProtectedPackage]
440
- ).returns(T::Array[::PackageProtections::RubocopProtectionInterface::CopConfig])
441
- end
442
- def cop_configs(packages); end
443
-
444
- sig { abstract.returns(::String) }
445
- def cop_name; end
446
-
447
- sig { returns(T::Hash[T.untyped, T.untyped]) }
448
- def custom_cop_config; end
449
-
450
- sig do
451
- override
452
- .params(
453
- protected_packages: T::Array[::PackageProtections::ProtectedPackage]
454
- ).returns(T::Array[::PackageProtections::Offense])
455
- end
456
- def get_offenses_for_existing_violations(protected_packages); end
457
-
458
- sig do
459
- override
460
- .params(
461
- new_violations: T::Array[::PackageProtections::PerFileViolation]
462
- ).returns(T::Array[::PackageProtections::Offense])
463
- end
464
- def get_offenses_for_new_violations(new_violations); end
465
-
466
- sig { abstract.returns(T::Array[::String]) }
467
- def included_globs_for_pack; end
468
-
469
- sig { abstract.params(file: ::String).returns(::String) }
470
- def message_for_fail_on_any(file); end
471
-
472
- sig do
473
- override
474
- .params(
475
- behavior: ::PackageProtections::ViolationBehavior,
476
- package: ::ParsePackwerk::Package
477
- ).returns(T.nilable(::String))
478
- end
479
- def unmet_preconditions_for_behavior(behavior, package); end
480
- end
481
-
482
- class PackageProtections::RubocopProtectionInterface::CopConfig < ::T::Struct
483
- const :enabled, T::Boolean, default: T.unsafe(nil)
484
- const :exclude_paths, T::Array[::String], default: T.unsafe(nil)
485
- const :include_paths, T::Array[::String], default: T.unsafe(nil)
486
- const :metadata, T.untyped, default: T.unsafe(nil)
487
- const :name, ::String
488
-
489
- sig { returns(::String) }
490
- def to_rubocop_yml_compatible_format; end
491
-
492
- class << self
493
- def inherited(s); end
494
- end
495
- end
496
-
497
- class PackageProtections::ViolationBehavior < ::T::Enum
498
- enums do
499
- FailOnAny = new
500
- FailOnNew = new
501
- FailNever = new
502
- end
503
-
504
- sig { returns(T::Boolean) }
505
- def enabled?; end
506
-
507
- sig { returns(T::Boolean) }
508
- def fail_never?; end
509
-
510
- sig { returns(T::Boolean) }
511
- def fail_on_any?; end
512
-
513
- sig { returns(T::Boolean) }
514
- def fail_on_new?; end
515
-
516
- class << self
517
- sig { params(value: T.untyped).returns(::PackageProtections::ViolationBehavior) }
518
- def from_raw_value(value); end
519
- end
520
- end
521
-
522
- module RuboCop; end
523
- module RuboCop::Cop; end
524
- module RuboCop::Cop::PackageProtections; end
525
-
526
- RuboCop::Cop::PackageProtections::OnlyClassMethods::IDENTIFIER = T.let(T.unsafe(nil), String)