query_packwerk 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,92 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require 'sorbet-runtime'
5
+ require 'parse_packwerk'
6
+ require 'rubocop'
7
+
8
+ #
9
+ # QueryPackwerk is a tool for querying Packwerk violations.
10
+ #
11
+ # It is built on top of ParsePackwerk, and provides a Ruby-friendly API
12
+ # for querying package.yml and package_todo.yml files.
13
+ #
14
+ module QueryPackwerk
15
+ autoload :Console, 'query_packwerk/console'
16
+ autoload :ConsoleHelpers, 'query_packwerk/console_helpers'
17
+ autoload :QueryInterface, 'query_packwerk/query_interface'
18
+ autoload :Violations, 'query_packwerk/violations'
19
+ autoload :Violation, 'query_packwerk/violation'
20
+ autoload :Packages, 'query_packwerk/packages'
21
+ autoload :Package, 'query_packwerk/package'
22
+ autoload :RuleRewriter, 'query_packwerk/rule_rewriter'
23
+ autoload :FileCache, 'query_packwerk/file_cache'
24
+ autoload :Version, 'query_packwerk/version'
25
+
26
+ extend T::Sig
27
+ # TODO: module_function isn't playing nicely with Sorbet
28
+ extend self # rubocop:todo Style/ModuleFunction
29
+
30
+ sig { params(name: String).returns(T.nilable(QueryPackwerk::Package)) }
31
+ def package(name)
32
+ Packages.where(name: name).first
33
+ end
34
+
35
+ # Get all violations where other packages access code from this package
36
+ # (i.e., this package is the producer, others are consumers)
37
+ sig { params(pack_name: String).returns(QueryPackwerk::Violations) }
38
+ def violations_for(pack_name)
39
+ QueryPackwerk::Violations.where(producing_pack: full_name(pack_name))
40
+ end
41
+
42
+ # Get all todos where this package accesses code from other packages
43
+ # (i.e., this package is the consumer, others are producers)
44
+ sig { params(pack_name: String).returns(QueryPackwerk::Violations) }
45
+ def todos_for(pack_name)
46
+ QueryPackwerk::Violations.where(consuming_pack: full_name(pack_name))
47
+ end
48
+
49
+ # Get where the violations occurred (where other packages access this package)
50
+ sig { params(pack_name: String).returns(T::Hash[String, T::Array[String]]) }
51
+ def violation_sources_for(pack_name)
52
+ violations_for(pack_name).sources_with_locations
53
+ end
54
+
55
+ # Get how often the violations occurred
56
+ sig { params(pack_name: String, threshold: Integer).returns(T::Hash[String, T::Hash[String, Integer]]) }
57
+ def violation_counts_for(pack_name, threshold: 0)
58
+ violations_for(pack_name).source_counts(threshold: threshold)
59
+ end
60
+
61
+ # Get the 'shape' of all violations (how other packages access this package)
62
+ sig { params(pack_name: String).returns(T::Hash[String, T::Array[String]]) }
63
+ def anonymous_violation_sources_for(pack_name)
64
+ violations_for(pack_name).anonymous_sources
65
+ end
66
+
67
+ # Get how often each 'shape' of violation occurs (counts of how other packages access this package)
68
+ sig { params(pack_name: String, threshold: Integer).returns(T::Hash[String, T::Hash[String, Integer]]) }
69
+ def anonymous_violation_counts_for(pack_name, threshold: 0)
70
+ violations_for(pack_name).anonymous_source_counts(threshold: threshold)
71
+ end
72
+
73
+ # Get which packages consume code from this package (who depends on this package)
74
+ sig { params(pack_name: String, threshold: Integer).returns(T::Hash[String, Integer]) }
75
+ def consumers(pack_name, threshold: 0)
76
+ violations_for(pack_name).consumers(threshold: threshold)
77
+ end
78
+
79
+ # In case anyone is still using shorthand for pack names
80
+ sig { params(pack_name: String).returns(String) }
81
+ def full_name(pack_name)
82
+ return pack_name if pack_name.match?(%r{\A(packs|components)/})
83
+
84
+ "packs/#{pack_name}"
85
+ end
86
+
87
+ sig { void }
88
+ def reload!
89
+ Packages.reload!
90
+ Violations.reload!
91
+ end
92
+ end
@@ -0,0 +1,4 @@
1
+ module QueryPackwerk
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,153 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: query_packwerk
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Gusto Engineering
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 2025-03-27 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: coderay
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: packwerk
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ - !ruby/object:Gem::Dependency
41
+ name: parse_packwerk
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ type: :runtime
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ - !ruby/object:Gem::Dependency
55
+ name: rubocop
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ type: :runtime
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ - !ruby/object:Gem::Dependency
69
+ name: sorbet-runtime
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ type: :runtime
76
+ prerelease: false
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ - !ruby/object:Gem::Dependency
83
+ name: thor
84
+ requirement: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ type: :runtime
90
+ prerelease: false
91
+ version_requirements: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ description: Query Packwerk violations and dependencies.
97
+ email:
98
+ - dev@gusto.com
99
+ executables:
100
+ - query_packwerk
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".rspec"
105
+ - ".rubocop.yml"
106
+ - CHANGELOG.md
107
+ - CODE_OF_CONDUCT.md
108
+ - LICENSE.txt
109
+ - README.md
110
+ - exe/query_packwerk
111
+ - lib/query_packwerk.rb
112
+ - lib/query_packwerk/cli.rb
113
+ - lib/query_packwerk/console.rb
114
+ - lib/query_packwerk/console_helpers.rb
115
+ - lib/query_packwerk/file_cache.rb
116
+ - lib/query_packwerk/package.rb
117
+ - lib/query_packwerk/packages.rb
118
+ - lib/query_packwerk/query_interface.rb
119
+ - lib/query_packwerk/rule_rewriter.rb
120
+ - lib/query_packwerk/rule_rewriter/anonymize_arguments_rule.rb
121
+ - lib/query_packwerk/rule_rewriter/anonymize_keyword_arguments_rule.rb
122
+ - lib/query_packwerk/rule_rewriter/base_rule.rb
123
+ - lib/query_packwerk/rule_rewriter/rule_set_rewriter.rb
124
+ - lib/query_packwerk/version.rb
125
+ - lib/query_packwerk/violation.rb
126
+ - lib/query_packwerk/violations.rb
127
+ - sig/query_packwerk.rbs
128
+ homepage: https://github.com/gusto/query_packwerk
129
+ licenses:
130
+ - MIT
131
+ metadata:
132
+ allowed_push_host: https://rubygems.org
133
+ homepage_uri: https://github.com/gusto/query_packwerk
134
+ source_code_uri: https://github.com/gusto/query_packwerk
135
+ changelog_uri: https://github.com/gusto/query_packwerk/blob/main/CHANGELOG.md
136
+ rdoc_options: []
137
+ require_paths:
138
+ - lib
139
+ required_ruby_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ version: 3.1.0
144
+ required_rubygems_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ requirements: []
150
+ rubygems_version: 3.6.2
151
+ specification_version: 4
152
+ summary: Query Packwerk
153
+ test_files: []