packwerk 3.2.0 → 3.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (126) hide show
  1. checksums.yaml +4 -4
  2. data/lib/packwerk/checker.rb +3 -3
  3. data/lib/packwerk/offenses_formatter.rb +3 -3
  4. data/lib/packwerk/package_todo.rb +1 -4
  5. data/lib/packwerk/parsers/factory.rb +3 -3
  6. data/lib/packwerk/parsers/ruby.rb +7 -0
  7. data/lib/packwerk/reference_offense.rb +1 -1
  8. data/lib/packwerk/validator.rb +3 -3
  9. data/lib/packwerk/version.rb +1 -1
  10. data/sorbet/rbi/gems/actionpack@7.0.3.1.rbi +3280 -3450
  11. data/sorbet/rbi/gems/actionview@7.0.3.1.rbi +2322 -1782
  12. data/sorbet/rbi/gems/activesupport@7.0.3.1.rbi +2654 -3268
  13. data/sorbet/rbi/gems/ast@2.4.2.rbi +535 -6
  14. data/sorbet/rbi/gems/better_html@2.0.1.rbi +529 -0
  15. data/sorbet/rbi/gems/builder@3.2.4.rbi +4 -4
  16. data/sorbet/rbi/gems/byebug@11.1.3.rbi +32 -4
  17. data/sorbet/rbi/gems/concurrent-ruby@1.1.10.rbi +1750 -1840
  18. data/sorbet/rbi/gems/constant_resolver@0.2.0.rbi +15 -15
  19. data/sorbet/rbi/gems/crass@1.0.6.rbi +489 -5
  20. data/sorbet/rbi/gems/erubi@1.11.0.rbi +24 -21
  21. data/sorbet/rbi/gems/i18n@1.12.0.rbi +395 -395
  22. data/sorbet/rbi/gems/json@2.6.2.rbi +70 -77
  23. data/sorbet/rbi/gems/language_server-protocol@3.16.0.3.rbi +1 -1
  24. data/sorbet/rbi/gems/loofah@2.18.0.rbi +134 -134
  25. data/sorbet/rbi/gems/m@1.6.0.rbi +60 -60
  26. data/sorbet/rbi/gems/method_source@1.1.0.rbi +303 -0
  27. data/sorbet/rbi/gems/minitest-focus@1.3.1.rbi +22 -28
  28. data/sorbet/rbi/gems/minitest@5.16.2.rbi +384 -396
  29. data/sorbet/rbi/gems/mocha@1.14.0.rbi +589 -589
  30. data/sorbet/rbi/gems/netrc@0.11.0.rbi +37 -32
  31. data/sorbet/rbi/gems/nokogiri@1.15.3.rbi +962 -946
  32. data/sorbet/rbi/gems/{parallel@1.22.1.rbi → parallel@1.24.0.rbi} +85 -82
  33. data/sorbet/rbi/gems/{parser@3.2.2.0.rbi → parser@3.3.1.0.rbi} +1679 -1609
  34. data/sorbet/rbi/gems/prettier_print@0.1.0.rbi +1 -1
  35. data/sorbet/rbi/gems/{prism@0.24.0.rbi → prism@0.27.0.rbi} +13473 -6472
  36. data/sorbet/rbi/gems/{racc@1.6.0.rbi → racc@1.7.1.rbi} +42 -33
  37. data/sorbet/rbi/gems/rack-test@2.0.2.rbi +148 -338
  38. data/sorbet/rbi/gems/rack@2.2.4.rbi +1079 -1130
  39. data/sorbet/rbi/gems/rails-dom-testing@2.0.3.rbi +354 -22
  40. data/sorbet/rbi/gems/rails-html-sanitizer@1.4.3.rbi +113 -259
  41. data/sorbet/rbi/gems/railties@7.0.3.1.rbi +642 -638
  42. data/sorbet/rbi/gems/rainbow@3.1.1.rbi +109 -99
  43. data/sorbet/rbi/gems/rake@13.0.6.rbi +714 -599
  44. data/sorbet/rbi/gems/{rbi@0.0.15.rbi → rbi@0.1.12.rbi} +865 -801
  45. data/sorbet/rbi/gems/regexp_parser@2.5.0.rbi +853 -870
  46. data/sorbet/rbi/gems/rexml@3.2.5.rbi +480 -477
  47. data/sorbet/rbi/gems/rubocop-ast@1.21.0.rbi +1621 -1622
  48. data/sorbet/rbi/gems/rubocop-performance@1.14.3.rbi +507 -526
  49. data/sorbet/rbi/gems/rubocop-shopify@2.9.0.rbi +1 -1
  50. data/sorbet/rbi/gems/rubocop-sorbet@0.6.11.rbi +186 -203
  51. data/sorbet/rbi/gems/rubocop@1.34.1.rbi +8126 -8367
  52. data/sorbet/rbi/gems/{ruby-lsp@0.2.1.rbi → ruby-lsp@0.2.3.rbi} +2 -2
  53. data/sorbet/rbi/gems/ruby-progressbar@1.11.0.rbi +1235 -4
  54. data/sorbet/rbi/gems/smart_properties@1.17.0.rbi +90 -90
  55. data/sorbet/rbi/gems/spoom@1.3.2.rbi +4420 -0
  56. data/sorbet/rbi/gems/spring@4.0.0.rbi +104 -104
  57. data/sorbet/rbi/gems/syntax_tree@3.3.0.rbi +1 -1
  58. data/sorbet/rbi/gems/{tapioca@0.9.2.rbi → tapioca@0.13.3.rbi} +1596 -1253
  59. data/sorbet/rbi/gems/{thor@1.2.1.rbi → thor@1.3.1.rbi} +1047 -652
  60. data/sorbet/rbi/gems/tzinfo@2.0.5.rbi +531 -513
  61. data/sorbet/rbi/gems/unicode-display_width@2.2.0.rbi +13 -13
  62. data/sorbet/rbi/gems/{yard-sorbet@0.6.1.rbi → yard-sorbet@0.8.1.rbi} +132 -92
  63. data/sorbet/rbi/gems/{yard@0.9.28.rbi → yard@0.9.36.rbi} +3158 -3067
  64. data/sorbet/rbi/gems/zeitwerk@2.6.4.rbi +149 -145
  65. metadata +18 -76
  66. data/.github/ISSUE_TEMPLATE/bug_report.md +0 -27
  67. data/.github/pull_request_template.md +0 -28
  68. data/.github/workflows/ci.yml +0 -93
  69. data/.github/workflows/cla.yml +0 -22
  70. data/.gitignore +0 -13
  71. data/.rubocop.yml +0 -75
  72. data/.ruby-version +0 -1
  73. data/CODEOWNERS +0 -1
  74. data/CODE_OF_CONDUCT.md +0 -76
  75. data/CONTRIBUTING.md +0 -17
  76. data/Gemfile +0 -27
  77. data/Gemfile.lock +0 -206
  78. data/RESOLVING_VIOLATIONS.md +0 -76
  79. data/Rakefile +0 -22
  80. data/TROUBLESHOOT.md +0 -44
  81. data/UPGRADING.md +0 -66
  82. data/USAGE.md +0 -364
  83. data/bin/console +0 -15
  84. data/bin/m +0 -29
  85. data/bin/rake +0 -29
  86. data/bin/rubocop +0 -29
  87. data/bin/setup +0 -8
  88. data/bin/srb +0 -29
  89. data/bin/tapioca +0 -29
  90. data/dev.yml +0 -32
  91. data/docs/cohesion.png +0 -0
  92. data/gemfiles/Gemfile-rails-6-0 +0 -22
  93. data/gemfiles/Gemfile-rails-6-1 +0 -22
  94. data/packwerk.gemspec +0 -59
  95. data/shipit.rubygems.yml +0 -5
  96. data/sorbet/rbi/gems/actioncable@7.0.3.1.rbi +0 -2754
  97. data/sorbet/rbi/gems/actionmailbox@7.0.3.1.rbi +0 -1496
  98. data/sorbet/rbi/gems/actionmailer@7.0.3.1.rbi +0 -2362
  99. data/sorbet/rbi/gems/actiontext@7.0.3.1.rbi +0 -1569
  100. data/sorbet/rbi/gems/activejob@7.0.3.1.rbi +0 -2553
  101. data/sorbet/rbi/gems/activemodel@7.0.3.1.rbi +0 -5999
  102. data/sorbet/rbi/gems/activerecord@7.0.3.1.rbi +0 -37832
  103. data/sorbet/rbi/gems/activestorage@7.0.3.1.rbi +0 -2321
  104. data/sorbet/rbi/gems/better_html@1.0.16.rbi +0 -317
  105. data/sorbet/rbi/gems/coderay@1.1.3.rbi +0 -8
  106. data/sorbet/rbi/gems/diff-lcs@1.5.0.rbi +0 -1079
  107. data/sorbet/rbi/gems/digest@3.1.0.rbi +0 -189
  108. data/sorbet/rbi/gems/globalid@1.0.0.rbi +0 -572
  109. data/sorbet/rbi/gems/mail@2.7.1.rbi +0 -2490
  110. data/sorbet/rbi/gems/marcel@1.0.2.rbi +0 -220
  111. data/sorbet/rbi/gems/method_source@1.0.0.rbi +0 -76
  112. data/sorbet/rbi/gems/mini_mime@1.1.2.rbi +0 -170
  113. data/sorbet/rbi/gems/net-imap@0.2.3.rbi +0 -2147
  114. data/sorbet/rbi/gems/net-pop@0.1.1.rbi +0 -926
  115. data/sorbet/rbi/gems/net-protocol@0.1.3.rbi +0 -11
  116. data/sorbet/rbi/gems/net-smtp@0.3.1.rbi +0 -1108
  117. data/sorbet/rbi/gems/nio4r@2.5.8.rbi +0 -292
  118. data/sorbet/rbi/gems/pry@0.14.1.rbi +0 -8
  119. data/sorbet/rbi/gems/rails@7.0.3.1.rbi +0 -8
  120. data/sorbet/rbi/gems/spoom@1.1.11.rbi +0 -2181
  121. data/sorbet/rbi/gems/strscan@3.0.4.rbi +0 -8
  122. data/sorbet/rbi/gems/timeout@0.3.0.rbi +0 -142
  123. data/sorbet/rbi/gems/unparser@0.6.5.rbi +0 -4529
  124. data/sorbet/rbi/gems/webrick@1.7.0.rbi +0 -2582
  125. data/sorbet/rbi/gems/websocket-driver@0.7.5.rbi +0 -993
  126. data/sorbet/rbi/gems/websocket-extensions@0.1.5.rbi +0 -71
data/USAGE.md DELETED
@@ -1,364 +0,0 @@
1
- # Packwerk usage
2
-
3
- ## Table of Contents
4
-
5
- * [What problem does Packwerk solve?](#what-problem-does-packwerk-solve)
6
- * [What is a package?](#what-is-a-package)
7
- * [Package principles](#package-principles)
8
- * [Getting started](#getting-started)
9
- * [Setting up Spring](#setting-up-spring)
10
- * [Configuring Packwerk](#configuring-packwerk)
11
- * [Using a custom ERB parser](#using-a-custom-erb-parser)
12
- * [Validating the package system](#validating-the-package-system)
13
- * [Defining packages](#defining-packages)
14
- * [Package metadata](#package-metadata)
15
- * [Types of boundary checks](#types-of-boundary-checks)
16
- * [Enforcing dependency boundary](#enforcing-dependency-boundary)
17
- * [Using strict mode](#using-strict-mode)
18
- * [Checking for violations](#checking-for-violations)
19
- * [Resolving new violations](#resolving-new-violations)
20
- * [Understanding how to respond to new violations](#understanding-how-to-respond-to-new-violations)
21
- * [Recording existing violations](#recording-existing-violations)
22
- * [Understanding the package todo file](#understanding-the-package-todo-file)
23
- * [Loading extensions](#loading-extensions)
24
-
25
- ## What problem does Packwerk solve?
26
-
27
- Large applications need clear boundaries to avoid turning into a [ball of mud](https://en.wikipedia.org/wiki/Big_ball_of_mud). However, Ruby does not provide a good solution to enforcing boundaries between code.
28
-
29
- Packwerk is a gem that can be used to enforce boundaries between groups of code we call packages.
30
-
31
- ## What is a package?
32
-
33
- A package is a folder containing autoloaded code. To decide whether code belongs together in a package, these are some design best practices:
34
-
35
- - We should package things together that have high functional [cohesion](https://en.wikipedia.org/wiki/Cohesion_(computer_science)).
36
- - Packages should be relatively loosely coupled to each other.
37
-
38
- ![cohesion](docs/cohesion.png)
39
-
40
- ### Package principles
41
-
42
- Package principles help to guide the organization of classes in a large system. These principles can also be applied to packages in large and complex codebases.
43
-
44
- They are well described in Robert Martin's [Design Principles and Design Patterns](https://drive.google.com/file/d/0BwhCYaYDn8EgODUxZTJhOWEtMTZlMi00OWRiLTg0ZmEtZWQ5ODRlY2RmNDlk/view) (right after the SOLID principles).
45
-
46
- ## Getting started
47
-
48
- After including Packwerk in the Gemfile, you will first want to generate a binstub:
49
- You can do this by running `bundle binstub packwerk`, which will generate a [binstub](https://bundler.io/man/bundle-binstubs.1.html#DESCRIPTION) at `bin/packwerk`.
50
-
51
- Then, you can generate the necessary files to get Packwerk running by executing:
52
-
53
- bin/packwerk init
54
-
55
- Here is a list of files generated:
56
-
57
- | File | Location | Description |
58
- |-----------------------------|--------------|------------|
59
- | Packwerk configuration | packwerk.yml | See [Setting up the configuration file](#configuring-packwerk) |
60
- | Root package | package.yml | A package for the root folder |
61
-
62
- After that, you may begin creating packages for your application. See [Defining packages](#Defining-packages)
63
-
64
- ### Setting up Spring
65
-
66
- [Spring](https://github.com/rails/spring) is a preloader for Rails. Because `packwerk` loads `Rails`, it can be sped up dramatically by enabling spring. Packwerk supports the usage of Spring.
67
- Firstly, spring needs to know about the packwerk spring command when spring is loading. To do that, add `require 'packwerk/spring_command'` to `config/spring.rb` in your application.
68
- Secondly, to enable Spring, first run `bin/spring binstub packwerk` which will "springify" the generated binstub.
69
-
70
-
71
- ## Configuring Packwerk
72
-
73
- Packwerk reads from the `packwerk.yml` configuration file in the root directory. Packwerk will run with the default configuration if any of these settings are not specified.
74
-
75
- | Key | Default value | Description |
76
- |----------------------|-------------------------------------------|--------------|
77
- | include | **/*.{rb,rake,erb} | list of patterns for folder paths to include |
78
- | exclude | {bin,node_modules,script,tmp,vendor}/**/* | list of patterns for folder paths to exclude |
79
- | package_paths | **/ | a single pattern or a list of patterns to find package configuration files, see: [Defining packages](#Defining-packages) |
80
- | custom_associations | N/A | list of custom associations, if any |
81
- | parallel | true | when true, fork code parsing out to subprocesses |
82
- | cache | false | when true, caches the results of parsing files |
83
- | cache_directory | tmp/cache/packwerk | the directory that will hold the packwerk cache |
84
-
85
- ### Using a custom ERB parser
86
-
87
- You can specify a custom ERB parser if needed. For example, if you're using `<%graphql>` tags from https://github.com/github/graphql-client in your ERBs, you can use a custom parser subclass to comment them out so that Packwerk can parse the rest of the file:
88
-
89
- ```ruby
90
- class CustomParser < Packwerk::Parsers::Erb
91
- def parse_buffer(buffer, file_path:)
92
- preprocessed_source = buffer.source
93
-
94
- # Comment out <%graphql ... %> tags. They won't contain any object
95
- # references anyways.
96
- preprocessed_source = preprocessed_source.gsub(/<%graphql/, "<%#")
97
-
98
- preprocessed_buffer = Parser::Source::Buffer.new(file_path)
99
- preprocessed_buffer.source = preprocessed_source
100
- super(preprocessed_buffer, file_path: file_path)
101
- end
102
- end
103
-
104
- Packwerk::Parsers::Factory.instance.erb_parser_class = CustomParser
105
- ```
106
-
107
- ## Using the cache
108
- Packwerk ships with an cache to help speed up file parsing. You can turn this on by setting `cache: true` in `packwerk.yml`.
109
-
110
- This will write to `tmp/cache/packwerk`.
111
-
112
- ## Validating the package system
113
-
114
- There are some criteria that an application must meet in order to have a valid package system. These criteria include having a valid autoload path cache, package definition files, and application folder structure. The dependency graph within the package system also has to be acyclic.
115
-
116
- We recommend setting up the package system validation for your Rails application in a CI step (or through a test suite for Ruby projects) separate from `bin/packwerk check`.
117
-
118
- Use the following command to validate the application:
119
-
120
- bin/packwerk validate
121
-
122
- ![](static/packwerk_validate.gif)
123
-
124
- ## Defining packages
125
-
126
- You can create a `package.yml` in any folder to make it a package. The package name is the path to the folder from the project root.
127
-
128
- _Note: It is helpful to define a namespace that corresponds to the package name and contains at least all the public constants of the package. This makes it more obvious which package a constant is defined in._
129
-
130
- ### Package metadata
131
-
132
- Package metadata can be included in the `package.yml`. Metadata won't be validated, and can thus be anything. We recommend including information on ownership and stewardship of the package.
133
-
134
- Example:
135
- ```yaml
136
- # components/sales/package.yml
137
- metadata:
138
- stewards:
139
- - "@Shopify/sales"
140
- slack_channels:
141
- - "#sales"
142
- ```
143
-
144
- ## Types of boundary checks
145
-
146
- Packwerk ships with dependency boundary checking only. Other checking support may be added by extension gems.
147
-
148
- #### Enforcing dependency boundary
149
-
150
- A package's dependency boundary is violated whenever it references a constant in some package that has not been declared as a dependency.
151
-
152
- Specify `enforce_dependencies: true` to start enforcing the dependencies of a package. The intentional dependencies of the package are specified as a list under a `dependencies:` key.
153
-
154
- Example:
155
-
156
- ```yaml
157
- # components/shop_identity/package.yml
158
- enforce_dependencies: true
159
- dependencies:
160
- - components/platform
161
- ```
162
-
163
- It will be a dependency violation when `components/shop_identity` tries to reference a constant that is not within `components/platform` or itself.
164
-
165
- #### Using strict mode
166
-
167
- You can turn on `strict` mode to prevent new violations from being added to the package's `package_todo.yml`. To use this, simply change `enforce_dependencies: true` to `enforce_dependencies: strict` in your `package.yml`.
168
-
169
- Then, when you run `bin/packwerk check`, new violations will cause the following error to be displayed:
170
- ```
171
- packs/referencing_package cannot have dependency violations on packs/defining_package because strict mode is enabled for dependency violations in packs/referencing_package/package.yml
172
- ```
173
-
174
- Once the `strict` mode is enabled on a package, running `bin/packwerk update-todo` will not add new violations in the package_todo.yml file and the command will return an error.
175
-
176
- ## Checking for violations
177
-
178
- After enforcing the boundary checks for a package, you may execute:
179
-
180
- bin/packwerk check
181
-
182
- Packwerk will check the entire codebase for any new or stale violations.
183
-
184
- You can also specify folders for a shorter run time. When checking against folders all subfolders will be analyzed, irrespective of nested package boundaries.
185
-
186
- bin/packwerk check components/your_package
187
-
188
- You can also specify packages for a shorter run time. When checking against packages any packages nested underneath the specified packages will not be checked. This can be helpful to test packages like the root package, which can have many nested packages.
189
-
190
- bin/packwerk check --packages=components/your_package,components/your_other_package
191
-
192
- Using the following command line option you can also enable or disable parallel processing. It is enabled by default.
193
-
194
- bin/packwerk check --[no-]parallel
195
-
196
- ![](static/packwerk_check.gif)
197
-
198
- In order to keep the package system valid at each version of the application, we recommend running `bin/packwerk check` in your CI pipeline.
199
-
200
- See: [TROUBLESHOOT.md - Sample violations](TROUBLESHOOT.md#Sample-violations)
201
-
202
- ## Resolving new violations
203
-
204
- ### Understanding how to respond to new violations
205
-
206
- When you have a new dependency violation, what do you do?
207
-
208
- See: [RESOLVING_VIOLATIONS.md](RESOLVING_VIOLATIONS.md)
209
-
210
- ## Recording existing violations
211
-
212
- For existing codebases, packages are likely to have existing boundary violations.
213
-
214
- If so, you will want to stop the bleeding and prevent more violations from occuring. The existing violations in the codebase can be recorded in a [todo list](#understanding-the-package-todo-file) by executing:
215
-
216
- bin/packwerk update-todo
217
-
218
- ![](static/packwerk_update.gif)
219
-
220
- `bin/packwerk update-todo` should only be run to record existing violations and to remove violations that have been worked off. Running `bin/packwerk update-todo` to resolve a violation should be the very last resort.
221
-
222
- See: [TROUBLESHOOT.md - Troubleshooting violations](TROUBLESHOOT.md#Troubleshooting_violations)
223
-
224
- ### Understanding the package todo file
225
-
226
- The package TODO list is called `package_todo.yml` and can be found in the package folder. The list outlines the constant violations of the package, where the violation is located, and the file defining the violation.
227
-
228
- The package TODO list should not be added to, but worked off over time.
229
-
230
- ```yaml
231
- components/merchant:
232
- "::Checkouts::Core::CheckoutId":
233
- violations:
234
- - dependency
235
- files:
236
- - components/merchant/app/public/merchant/generate_order.rb
237
- ```
238
-
239
- Above is an example of a constant violation entry in `package_todo.yml`.
240
-
241
- * `components/merchant` - package where the constant violation is found
242
- * `::Checkouts::Core::CheckoutId` - violated constant in question
243
- * `dependency` - type of violation, typically dependency
244
- * `components/merchant/app/public/merchant/generate_order.rb` - path to the file containing the violated constant
245
-
246
- Violations exist within the package that makes a violating reference.
247
-
248
- # Loading Extensions
249
-
250
- You can optionally specify ruby files that you'd like to be loaded with `packwerk` by specifying a `require` directive in `packwerk.yml`:
251
- ```yml
252
- require:
253
- - ./path/to/file.rb
254
- - my_gem
255
- ```
256
-
257
- `packwerk` will directly call `require` with these paths.
258
- You can prefix local files with a dot to define them relative to `packwerk.yml`, or you can use absolute paths.
259
- You can also reference the name of a gem.
260
-
261
- ## Examples
262
-
263
- ### Custom Offense Formatter
264
-
265
- While `packwerk` ships with its own offense formatter, you may specify a custom one in your configuration file via the `offenses_formatter:` key. Your custom formatter will be used when `bin/packwerk check` is run.
266
-
267
- Firstly, you'll need to create an `OffensesFormatter` class that includes `Packwerk::OffensesFormatter`. You can use [`Packwerk::Formatters::OffensesFormatter`](lib/packwerk/formatters/offenses_formatter.rb) as a point of reference for this. Then, in the `require` directive described above, you'll want to tell `packwerk` about it:
268
- ```ruby
269
- # ./path/to/file.rb
270
- class MyOffensesFormatter
271
- include Packwerk::OffensesFormatter
272
- # implement the `OffensesFormatter` interface
273
-
274
- def identifier
275
- 'my_offenses_formatter'
276
- end
277
- end
278
- ```
279
-
280
- Then in `packwerk.yml`, you can set the `formatter` to the identifier for your class:
281
- ```yml
282
- offenses_formatter: my_offenses_formatter
283
- ```
284
-
285
- You can also pass in a formatter on the command line:
286
- ```
287
- bin/packwerk check --offenses-formatter=my_offenses_formatter
288
- ```
289
-
290
- ### Custom Checkers
291
-
292
- Packwerk ships with a way to analyze dependencies and also supports custom checkers from extension gems.
293
-
294
- Custom checkers will allow references to constants to be analyzed in new ways, and for those invalid references to show up as violations in `package_todo.yml`.
295
-
296
- To create a custom checker, you'll first need to create a checker class that includes `Packwerk::Checker`. You can use [`Packwerk::ReferenceChecking::Checkers::DependencyChecker`](lib/packwerk/reference_checking/checkers/dependency_checker.rb) as a point of reference for this. Here is an example:
297
-
298
- ```ruby
299
- # ./path/to/file.rb
300
- class MyChecker
301
- include Packwerk::Checker
302
- # implement the `Checker` interface
303
-
304
- sig { override.returns(String) }
305
- def violation_type
306
- 'my_custom_violation_type'
307
- end
308
-
309
- sig { override.params(listed_offense: ReferenceOffense).returns(T::Boolean) }
310
- def strict_mode_violation?(listed_offense)
311
- # This will allow "strict mode" to be supported in your checker
312
- referencing_package = listed_offense.reference.package
313
- referencing_package.config["enforce_custom"] == "strict"
314
- end
315
-
316
- sig { override.params(reference: Reference).returns(T::Boolean) }
317
- def invalid_reference?(reference)
318
- # your logic here
319
- end
320
-
321
- sig { override.params(reference: Reference).returns(String) }
322
- def message(reference)
323
- # your message here
324
- end
325
- end
326
- ```
327
-
328
- Then, in the `require` directive described above, you'll want to tell `packwerk` about it:
329
-
330
- ```yml
331
- require:
332
- - ./path/to/file.rb
333
- ```
334
-
335
- ### Custom Validators
336
-
337
- Similar to checkers, you can define your own validator to be executed when `bin/packwerk validate` is invoked. This can be used to support your custom checker (by specifying permitted keys) or to provide any other validations you want to impose on packages.
338
-
339
- To create a custom validator, you'll first need to create a validator class that includes `Packwerk::Validator`. You can use [`Packwerk::Validators::DependencyValidator`](lib/packwerk/validators/dependency_validator.rb) as a point of reference for this. Here is an example:
340
-
341
- ```ruby
342
- # ./path/to/file.rb
343
- class MyValidator
344
- include Packwerk::Validator
345
- # implement the `Validator` interface
346
-
347
- sig { override.returns(T::Array[String]) }
348
- def permitted_keys
349
- ['enforce_my_custom_checker']
350
- end
351
-
352
- sig { override.params(package_set: PackageSet, configuration: Configuration).returns(ApplicationValidator::Result) }
353
- def call(package_set, configuration)
354
- # your logic here
355
- end
356
- end
357
- ```
358
-
359
- Then, in the `require` directive described above, you'll want to tell `packwerk` about it:
360
-
361
- ```yml
362
- require:
363
- - ./path/to/file.rb
364
- ```
data/bin/console DELETED
@@ -1,15 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- require "bundler/setup"
5
- require "packwerk"
6
-
7
- # You can add fixtures and/or initialization code here to make experimenting
8
- # with your gem easier. You can also use a different console, if you like.
9
-
10
- # (If you use this, don't forget to add pry to your Gemfile!)
11
- # require "pry"
12
- # Pry.start
13
-
14
- require "irb"
15
- IRB.start(__FILE__)
data/bin/m DELETED
@@ -1,29 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- #
5
- # This file was generated by Bundler.
6
- #
7
- # The application 'm' is installed as part of a gem, and
8
- # this file is here to facilitate running it.
9
- #
10
-
11
- require "pathname"
12
- ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
- Pathname.new(__FILE__).realpath)
14
-
15
- bundle_binstub = File.expand_path("../bundle", __FILE__)
16
-
17
- if File.file?(bundle_binstub)
18
- if /This file was generated by Bundler/.match?(File.read(bundle_binstub, 300))
19
- load(bundle_binstub)
20
- else
21
- abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
- Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
- end
24
- end
25
-
26
- require "rubygems"
27
- require "bundler/setup"
28
-
29
- load Gem.bin_path("m", "m")
data/bin/rake DELETED
@@ -1,29 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- #
5
- # This file was generated by Bundler.
6
- #
7
- # The application 'rake' is installed as part of a gem, and
8
- # this file is here to facilitate running it.
9
- #
10
-
11
- require "pathname"
12
- ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
- Pathname.new(__FILE__).realpath)
14
-
15
- bundle_binstub = File.expand_path("../bundle", __FILE__)
16
-
17
- if File.file?(bundle_binstub)
18
- if /This file was generated by Bundler/.match?(File.read(bundle_binstub, 300))
19
- load(bundle_binstub)
20
- else
21
- abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
- Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
- end
24
- end
25
-
26
- require "rubygems"
27
- require "bundler/setup"
28
-
29
- load Gem.bin_path("rake", "rake")
data/bin/rubocop DELETED
@@ -1,29 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- #
5
- # This file was generated by Bundler.
6
- #
7
- # The application 'rubocop' is installed as part of a gem, and
8
- # this file is here to facilitate running it.
9
- #
10
-
11
- require "pathname"
12
- ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
- Pathname.new(__FILE__).realpath)
14
-
15
- bundle_binstub = File.expand_path("../bundle", __FILE__)
16
-
17
- if File.file?(bundle_binstub)
18
- if /This file was generated by Bundler/.match?(File.read(bundle_binstub, 300))
19
- load(bundle_binstub)
20
- else
21
- abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
- Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
- end
24
- end
25
-
26
- require "rubygems"
27
- require "bundler/setup"
28
-
29
- load Gem.bin_path("rubocop", "rubocop")
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
data/bin/srb DELETED
@@ -1,29 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- #
5
- # This file was generated by Bundler.
6
- #
7
- # The application 'srb' is installed as part of a gem, and
8
- # this file is here to facilitate running it.
9
- #
10
-
11
- require "pathname"
12
- ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
- Pathname.new(__FILE__).realpath)
14
-
15
- bundle_binstub = File.expand_path("../bundle", __FILE__)
16
-
17
- if File.file?(bundle_binstub)
18
- if /This file was generated by Bundler/.match?(File.read(bundle_binstub, 300))
19
- load(bundle_binstub)
20
- else
21
- abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
- Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
- end
24
- end
25
-
26
- require "rubygems"
27
- require "bundler/setup"
28
-
29
- load Gem.bin_path("sorbet", "srb")
data/bin/tapioca DELETED
@@ -1,29 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- #
5
- # This file was generated by Bundler.
6
- #
7
- # The application 'tapioca' is installed as part of a gem, and
8
- # this file is here to facilitate running it.
9
- #
10
-
11
- require "pathname"
12
- ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
- Pathname.new(__FILE__).realpath)
14
-
15
- bundle_binstub = File.expand_path("../bundle", __FILE__)
16
-
17
- if File.file?(bundle_binstub)
18
- if /This file was generated by Bundler/.match?(File.read(bundle_binstub, 300))
19
- load(bundle_binstub)
20
- else
21
- abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
- Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
- end
24
- end
25
-
26
- require "rubygems"
27
- require "bundler/setup"
28
-
29
- load Gem.bin_path("tapioca", "tapioca")
data/dev.yml DELETED
@@ -1,32 +0,0 @@
1
- name: packwerk
2
-
3
- type: ruby
4
-
5
- up:
6
- - ruby: 3.2.2
7
- - bundler
8
-
9
- commands:
10
- test:
11
- run: |
12
- if [[ "$*" =~ ":"[0-9]+ ]];
13
- then
14
- # run test by its line number
15
- bin/m "$@"
16
- elif [[ "$#" -eq 1 && -f "$1" ]];
17
- then
18
- # run all tests in given file(s)
19
- bin/rake test TEST="$@"
20
- else
21
- # run all tests
22
- bin/rake test
23
- fi
24
- style: "bin/rubocop -D --auto-correct"
25
- typecheck:
26
- desc: "run Sorbet typechecking"
27
- run: "bin/srb tc"
28
- aliases: ['tc']
29
- subcommands:
30
- update:
31
- desc: "update RBIs for gems"
32
- run: "bin/tapioca sync -c 'dev typecheck update'"
data/docs/cohesion.png DELETED
Binary file
@@ -1,22 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source("https://rubygems.org")
4
-
5
- gemspec path: ".."
6
-
7
- # Specify the same dependency sources as the application Gemfile
8
-
9
- gem("spring")
10
- gem("rails", "~> 6.0.0")
11
- gem("constant_resolver", require: false)
12
- gem("sorbet-runtime", require: false)
13
- gem("rubocop-performance", require: false)
14
- gem("rubocop-sorbet", require: false)
15
- gem("mocha", require: false)
16
- gem("rubocop-shopify", require: false)
17
- gem("tapioca", require: false)
18
-
19
- group :development do
20
- gem("byebug", require: false)
21
- gem("minitest-focus", require: false)
22
- end
@@ -1,22 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source("https://rubygems.org")
4
-
5
- gemspec path: ".."
6
-
7
- # Specify the same dependency sources as the application Gemfile
8
-
9
- gem("spring")
10
- gem("rails", "~> 6.1")
11
- gem("constant_resolver", require: false)
12
- gem("sorbet-runtime", require: false)
13
- gem("rubocop-performance", require: false)
14
- gem("rubocop-sorbet", require: false)
15
- gem("mocha", require: false)
16
- gem("rubocop-shopify", require: false)
17
- gem("tapioca", require: false)
18
-
19
- group :development do
20
- gem("byebug", require: false)
21
- gem("minitest-focus", require: false)
22
- end
data/packwerk.gemspec DELETED
@@ -1,59 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "lib/packwerk/version"
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = "packwerk"
7
- spec.version = Packwerk::VERSION
8
- spec.authors = ["Shopify Inc."]
9
- spec.email = ["gems@shopify.com"]
10
-
11
- spec.summary = "Packages for applications based on the zeitwerk autoloader"
12
-
13
- spec.description = <<~DESCRIPTION
14
- Sets package level boundaries between a specified set of ruby
15
- constants to minimize cross-boundary referencing and dependency.
16
- DESCRIPTION
17
- spec.homepage = "https://github.com/Shopify/packwerk"
18
- spec.license = "MIT"
19
-
20
- if spec.respond_to?(:metadata)
21
- spec.metadata["homepage_uri"] = spec.homepage
22
- spec.metadata["source_code_uri"] = "https://github.com/Shopify/packwerk"
23
- spec.metadata["changelog_uri"] = "https://github.com/Shopify/packwerk/releases"
24
- end
25
-
26
- if spec.respond_to?(:metadata)
27
- spec.metadata["allowed_push_host"] = "https://rubygems.org"
28
- else
29
- raise "RubyGems 2.0 or newer is required to protect against " \
30
- "public gem pushes."
31
- end
32
-
33
- spec.bindir = "exe"
34
- spec.executables << "packwerk"
35
-
36
- spec.files = Dir.chdir(__dir__) do
37
- %x(git ls-files -z).split("\x0").reject { |f| f.match(%r{^(test|spec|features|static)/}) }
38
- end
39
- spec.require_paths = ["lib"]
40
-
41
- spec.required_ruby_version = ">= 2.7"
42
-
43
- spec.add_dependency("activesupport", ">= 6.0")
44
- spec.add_dependency("bundler")
45
- spec.add_dependency("constant_resolver", ">= 0.2.0")
46
- spec.add_dependency("parallel")
47
- spec.add_dependency("sorbet-runtime", ">= 0.5.9914")
48
- spec.add_dependency("zeitwerk", ">= 2.6.1")
49
-
50
- # For Ruby parsing
51
- spec.add_dependency("ast")
52
- spec.add_dependency("parser")
53
- spec.add_dependency("prism", ">= 0.24.0") # 0.24.0 fixes a performance issue with the parser translator
54
-
55
- # For ERB parsing
56
- spec.add_dependency("better_html")
57
-
58
- spec.add_development_dependency("railties")
59
- end