packwerk 3.1.0 → 3.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. checksums.yaml +4 -4
  2. data/lib/packwerk/checker.rb +5 -5
  3. data/lib/packwerk/commands/check_command.rb +4 -2
  4. data/lib/packwerk/file_processor.rb +1 -1
  5. data/lib/packwerk/generators/templates/package.yml +2 -2
  6. data/lib/packwerk/offenses_formatter.rb +3 -3
  7. data/lib/packwerk/package_todo.rb +1 -4
  8. data/lib/packwerk/parsers/factory.rb +3 -3
  9. data/lib/packwerk/parsers/ruby.rb +9 -2
  10. data/lib/packwerk/reference_checking/checkers/dependency_checker.rb +3 -3
  11. data/lib/packwerk/reference_offense.rb +1 -1
  12. data/lib/packwerk/validator.rb +3 -3
  13. data/lib/packwerk/version.rb +1 -1
  14. data/sorbet/rbi/gems/actionpack@7.0.3.1.rbi +3280 -3450
  15. data/sorbet/rbi/gems/actionview@7.0.3.1.rbi +2322 -1782
  16. data/sorbet/rbi/gems/activesupport@7.0.3.1.rbi +2654 -3268
  17. data/sorbet/rbi/gems/ast@2.4.2.rbi +535 -6
  18. data/sorbet/rbi/gems/better_html@2.0.1.rbi +529 -0
  19. data/sorbet/rbi/gems/builder@3.2.4.rbi +4 -4
  20. data/sorbet/rbi/gems/byebug@11.1.3.rbi +32 -4
  21. data/sorbet/rbi/gems/concurrent-ruby@1.1.10.rbi +1750 -1840
  22. data/sorbet/rbi/gems/constant_resolver@0.2.0.rbi +15 -15
  23. data/sorbet/rbi/gems/crass@1.0.6.rbi +489 -5
  24. data/sorbet/rbi/gems/erubi@1.11.0.rbi +24 -21
  25. data/sorbet/rbi/gems/i18n@1.12.0.rbi +395 -395
  26. data/sorbet/rbi/gems/json@2.6.2.rbi +70 -77
  27. data/sorbet/rbi/gems/language_server-protocol@3.16.0.3.rbi +1 -1
  28. data/sorbet/rbi/gems/loofah@2.18.0.rbi +134 -134
  29. data/sorbet/rbi/gems/m@1.6.0.rbi +60 -60
  30. data/sorbet/rbi/gems/method_source@1.1.0.rbi +303 -0
  31. data/sorbet/rbi/gems/minitest-focus@1.3.1.rbi +22 -28
  32. data/sorbet/rbi/gems/minitest@5.16.2.rbi +384 -396
  33. data/sorbet/rbi/gems/mocha@1.14.0.rbi +589 -589
  34. data/sorbet/rbi/gems/netrc@0.11.0.rbi +37 -32
  35. data/sorbet/rbi/gems/{nokogiri@1.13.8.rbi → nokogiri@1.15.3.rbi} +1869 -1030
  36. data/sorbet/rbi/gems/{parallel@1.22.1.rbi → parallel@1.24.0.rbi} +85 -82
  37. data/sorbet/rbi/gems/{parser@3.2.2.0.rbi → parser@3.3.1.0.rbi} +1679 -1609
  38. data/sorbet/rbi/gems/prettier_print@0.1.0.rbi +1 -1
  39. data/sorbet/rbi/gems/prism@0.27.0.rbi +36983 -0
  40. data/sorbet/rbi/gems/{racc@1.6.0.rbi → racc@1.7.1.rbi} +42 -33
  41. data/sorbet/rbi/gems/rack-test@2.0.2.rbi +148 -338
  42. data/sorbet/rbi/gems/rack@2.2.4.rbi +1079 -1130
  43. data/sorbet/rbi/gems/rails-dom-testing@2.0.3.rbi +354 -22
  44. data/sorbet/rbi/gems/rails-html-sanitizer@1.4.3.rbi +113 -259
  45. data/sorbet/rbi/gems/railties@7.0.3.1.rbi +642 -638
  46. data/sorbet/rbi/gems/rainbow@3.1.1.rbi +109 -99
  47. data/sorbet/rbi/gems/rake@13.0.6.rbi +714 -599
  48. data/sorbet/rbi/gems/{rbi@0.0.15.rbi → rbi@0.1.12.rbi} +865 -801
  49. data/sorbet/rbi/gems/regexp_parser@2.5.0.rbi +853 -870
  50. data/sorbet/rbi/gems/rexml@3.2.5.rbi +480 -477
  51. data/sorbet/rbi/gems/rubocop-ast@1.21.0.rbi +1621 -1622
  52. data/sorbet/rbi/gems/rubocop-performance@1.14.3.rbi +507 -526
  53. data/sorbet/rbi/gems/rubocop-shopify@2.9.0.rbi +1 -1
  54. data/sorbet/rbi/gems/rubocop-sorbet@0.6.11.rbi +186 -203
  55. data/sorbet/rbi/gems/rubocop@1.34.1.rbi +8126 -8367
  56. data/sorbet/rbi/gems/{ruby-lsp@0.2.1.rbi → ruby-lsp@0.2.3.rbi} +2 -2
  57. data/sorbet/rbi/gems/ruby-progressbar@1.11.0.rbi +1235 -4
  58. data/sorbet/rbi/gems/smart_properties@1.17.0.rbi +90 -90
  59. data/sorbet/rbi/gems/spoom@1.3.2.rbi +4420 -0
  60. data/sorbet/rbi/gems/spring@4.0.0.rbi +104 -104
  61. data/sorbet/rbi/gems/syntax_tree@3.3.0.rbi +1 -1
  62. data/sorbet/rbi/gems/{tapioca@0.9.2.rbi → tapioca@0.13.3.rbi} +1596 -1253
  63. data/sorbet/rbi/gems/{thor@1.2.1.rbi → thor@1.3.1.rbi} +1047 -652
  64. data/sorbet/rbi/gems/tzinfo@2.0.5.rbi +531 -513
  65. data/sorbet/rbi/gems/unicode-display_width@2.2.0.rbi +13 -13
  66. data/sorbet/rbi/gems/{yard-sorbet@0.6.1.rbi → yard-sorbet@0.8.1.rbi} +132 -92
  67. data/sorbet/rbi/gems/{yard@0.9.28.rbi → yard@0.9.36.rbi} +3158 -3067
  68. data/sorbet/rbi/gems/zeitwerk@2.6.4.rbi +149 -145
  69. metadata +31 -74
  70. data/.github/ISSUE_TEMPLATE/bug_report.md +0 -27
  71. data/.github/pull_request_template.md +0 -28
  72. data/.github/workflows/ci.yml +0 -93
  73. data/.github/workflows/cla.yml +0 -22
  74. data/.gitignore +0 -13
  75. data/.rubocop.yml +0 -75
  76. data/.ruby-version +0 -1
  77. data/CODEOWNERS +0 -1
  78. data/CODE_OF_CONDUCT.md +0 -76
  79. data/CONTRIBUTING.md +0 -17
  80. data/Gemfile +0 -27
  81. data/Gemfile.lock +0 -206
  82. data/RESOLVING_VIOLATIONS.md +0 -76
  83. data/Rakefile +0 -22
  84. data/TROUBLESHOOT.md +0 -44
  85. data/UPGRADING.md +0 -66
  86. data/USAGE.md +0 -365
  87. data/bin/console +0 -15
  88. data/bin/m +0 -29
  89. data/bin/rake +0 -29
  90. data/bin/rubocop +0 -29
  91. data/bin/setup +0 -8
  92. data/bin/srb +0 -29
  93. data/bin/tapioca +0 -29
  94. data/dev.yml +0 -32
  95. data/docs/cohesion.png +0 -0
  96. data/gemfiles/Gemfile-rails-6-0 +0 -22
  97. data/gemfiles/Gemfile-rails-6-1 +0 -22
  98. data/packwerk.gemspec +0 -58
  99. data/shipit.rubygems.yml +0 -5
  100. data/sorbet/rbi/gems/actioncable@7.0.3.1.rbi +0 -2754
  101. data/sorbet/rbi/gems/actionmailbox@7.0.3.1.rbi +0 -1496
  102. data/sorbet/rbi/gems/actionmailer@7.0.3.1.rbi +0 -2362
  103. data/sorbet/rbi/gems/actiontext@7.0.3.1.rbi +0 -1569
  104. data/sorbet/rbi/gems/activejob@7.0.3.1.rbi +0 -2553
  105. data/sorbet/rbi/gems/activemodel@7.0.3.1.rbi +0 -5999
  106. data/sorbet/rbi/gems/activerecord@7.0.3.1.rbi +0 -37832
  107. data/sorbet/rbi/gems/activestorage@7.0.3.1.rbi +0 -2321
  108. data/sorbet/rbi/gems/better_html@1.0.16.rbi +0 -317
  109. data/sorbet/rbi/gems/coderay@1.1.3.rbi +0 -8
  110. data/sorbet/rbi/gems/diff-lcs@1.5.0.rbi +0 -1079
  111. data/sorbet/rbi/gems/digest@3.1.0.rbi +0 -189
  112. data/sorbet/rbi/gems/globalid@1.0.0.rbi +0 -572
  113. data/sorbet/rbi/gems/mail@2.7.1.rbi +0 -2490
  114. data/sorbet/rbi/gems/marcel@1.0.2.rbi +0 -220
  115. data/sorbet/rbi/gems/method_source@1.0.0.rbi +0 -76
  116. data/sorbet/rbi/gems/mini_mime@1.1.2.rbi +0 -170
  117. data/sorbet/rbi/gems/net-imap@0.2.3.rbi +0 -2147
  118. data/sorbet/rbi/gems/net-pop@0.1.1.rbi +0 -926
  119. data/sorbet/rbi/gems/net-protocol@0.1.3.rbi +0 -11
  120. data/sorbet/rbi/gems/net-smtp@0.3.1.rbi +0 -1108
  121. data/sorbet/rbi/gems/nio4r@2.5.8.rbi +0 -292
  122. data/sorbet/rbi/gems/pry@0.14.1.rbi +0 -8
  123. data/sorbet/rbi/gems/rails@7.0.3.1.rbi +0 -8
  124. data/sorbet/rbi/gems/spoom@1.1.11.rbi +0 -2181
  125. data/sorbet/rbi/gems/strscan@3.0.4.rbi +0 -8
  126. data/sorbet/rbi/gems/timeout@0.3.0.rbi +0 -142
  127. data/sorbet/rbi/gems/unparser@0.6.5.rbi +0 -4529
  128. data/sorbet/rbi/gems/webrick@1.7.0.rbi +0 -2582
  129. data/sorbet/rbi/gems/websocket-driver@0.7.5.rbi +0 -993
  130. data/sorbet/rbi/gems/websocket-extensions@0.1.5.rbi +0 -71
data/USAGE.md DELETED
@@ -1,365 +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
- * [Understanding the list of deprecated references](#understanding-the-list-of-deprecated-references)
24
- * [Loading extensions](#loading-extensions)
25
-
26
- ## What problem does Packwerk solve?
27
-
28
- 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.
29
-
30
- Packwerk is a gem that can be used to enforce boundaries between groups of code we call packages.
31
-
32
- ## What is a package?
33
-
34
- A package is a folder containing autoloaded code. To decide whether code belongs together in a package, these are some design best practices:
35
-
36
- - We should package things together that have high functional [cohesion](https://en.wikipedia.org/wiki/Cohesion_(computer_science)).
37
- - Packages should be relatively loosely coupled to each other.
38
-
39
- ![cohesion](docs/cohesion.png)
40
-
41
- ### Package principles
42
-
43
- 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.
44
-
45
- The [package principles](https://en.wikipedia.org/wiki/Package_principles) page on Wikipedia does a good job explaining what well designed packages look like.
46
-
47
- ## Getting started
48
-
49
- After including Packwerk in the Gemfile, you will first want to generate a binstub:
50
- 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`.
51
-
52
- Then, you can generate the necessary files to get Packwerk running by executing:
53
-
54
- bin/packwerk init
55
-
56
- Here is a list of files generated:
57
-
58
- | File | Location | Description |
59
- |-----------------------------|--------------|------------|
60
- | Packwerk configuration | packwerk.yml | See [Setting up the configuration file](#configuring-packwerk) |
61
- | Root package | package.yml | A package for the root folder |
62
-
63
- After that, you may begin creating packages for your application. See [Defining packages](#Defining-packages)
64
-
65
- ### Setting up Spring
66
-
67
- [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.
68
- 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.
69
- Secondly, to enable Spring, first run `bin/spring binstub packwerk` which will "springify" the generated binstub.
70
-
71
-
72
- ## Configuring Packwerk
73
-
74
- 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.
75
-
76
- | Key | Default value | Description |
77
- |----------------------|-------------------------------------------|--------------|
78
- | include | **/*.{rb,rake,erb} | list of patterns for folder paths to include |
79
- | exclude | {bin,node_modules,script,tmp,vendor}/**/* | list of patterns for folder paths to exclude |
80
- | package_paths | **/ | a single pattern or a list of patterns to find package configuration files, see: [Defining packages](#Defining-packages) |
81
- | custom_associations | N/A | list of custom associations, if any |
82
- | parallel | true | when true, fork code parsing out to subprocesses |
83
- | cache | false | when true, caches the results of parsing files |
84
- | cache_directory | tmp/cache/packwerk | the directory that will hold the packwerk cache |
85
-
86
- ### Using a custom ERB parser
87
-
88
- 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:
89
-
90
- ```ruby
91
- class CustomParser < Packwerk::Parsers::Erb
92
- def parse_buffer(buffer, file_path:)
93
- preprocessed_source = buffer.source
94
-
95
- # Comment out <%graphql ... %> tags. They won't contain any object
96
- # references anyways.
97
- preprocessed_source = preprocessed_source.gsub(/<%graphql/, "<%#")
98
-
99
- preprocessed_buffer = Parser::Source::Buffer.new(file_path)
100
- preprocessed_buffer.source = preprocessed_source
101
- super(preprocessed_buffer, file_path: file_path)
102
- end
103
- end
104
-
105
- Packwerk::Parsers::Factory.instance.erb_parser_class = CustomParser
106
- ```
107
-
108
- ## Using the cache
109
- Packwerk ships with an cache to help speed up file parsing. You can turn this on by setting `cache: true` in `packwerk.yml`.
110
-
111
- This will write to `tmp/cache/packwerk`.
112
-
113
- ## Validating the package system
114
-
115
- 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.
116
-
117
- 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`.
118
-
119
- Use the following command to validate the application:
120
-
121
- bin/packwerk validate
122
-
123
- ![](static/packwerk_validate.gif)
124
-
125
- ## Defining packages
126
-
127
- 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.
128
-
129
- _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._
130
-
131
- ### Package metadata
132
-
133
- 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.
134
-
135
- Example:
136
- ```yaml
137
- # components/sales/package.yml
138
- metadata:
139
- stewards:
140
- - "@Shopify/sales"
141
- slack_channels:
142
- - "#sales"
143
- ```
144
-
145
- ## Types of boundary checks
146
-
147
- Packwerk ships with dependency boundary checking only. Other checking support may be added by extension gems.
148
-
149
- #### Enforcing dependency boundary
150
-
151
- A package's dependency boundary is violated whenever it references a constant in some package that has not been declared as a dependency.
152
-
153
- 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.
154
-
155
- Example:
156
-
157
- ```yaml
158
- # components/shop_identity/package.yml
159
- enforce_dependencies: true
160
- dependencies:
161
- - components/platform
162
- ```
163
-
164
- It will be a dependency violation when `components/shop_identity` tries to reference a constant that is not within `components/platform` or itself.
165
-
166
- #### Using strict mode
167
-
168
- Once there are no more violations in a package, you can turn on `strict` mode, which will 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`.
169
-
170
- Then, when you run `bin/packwerk check`, new violations will cause the following error to be displayed:
171
- ```
172
- 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
173
- ```
174
-
175
- 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.
176
-
177
- ## Checking for violations
178
-
179
- After enforcing the boundary checks for a package, you may execute:
180
-
181
- bin/packwerk check
182
-
183
- Packwerk will check the entire codebase for any new or stale violations.
184
-
185
- You can also specify folders for a shorter run time. When checking against folders all subfolders will be analyzed, irrespective of nested package boundaries.
186
-
187
- bin/packwerk check components/your_package
188
-
189
- 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.
190
-
191
- bin/packwerk check --packages=components/your_package,components/your_other_package
192
-
193
- Using the following command line option you can also enable or disable parallel processing. It is enabled by default.
194
-
195
- bin/packwerk check --[no-]parallel
196
-
197
- ![](static/packwerk_check.gif)
198
-
199
- In order to keep the package system valid at each version of the application, we recommend running `bin/packwerk check` in your CI pipeline.
200
-
201
- See: [TROUBLESHOOT.md - Sample violations](TROUBLESHOOT.md#Sample-violations)
202
-
203
- ## Resolving new violations
204
-
205
- ### Understanding how to respond to new violations
206
-
207
- When you have a new dependency violation, what do you do?
208
-
209
- See: [RESOLVING_VIOLATIONS.md](RESOLVING_VIOLATIONS.md)
210
-
211
- ## Recording existing violations
212
-
213
- For existing codebases, packages are likely to have existing boundary violations.
214
-
215
- 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:
216
-
217
- bin/packwerk update-todo
218
-
219
- ![](static/packwerk_update.gif)
220
-
221
- `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.
222
-
223
- See: [TROUBLESHOOT.md - Troubleshooting violations](TROUBLESHOOT.md#Troubleshooting_violations)
224
-
225
- ### Understanding the package todo file
226
-
227
- 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.
228
-
229
- The package TODO list should not be added to, but worked off over time.
230
-
231
- ```yaml
232
- components/merchant:
233
- "::Checkouts::Core::CheckoutId":
234
- violations:
235
- - dependency
236
- files:
237
- - components/merchant/app/public/merchant/generate_order.rb
238
- ```
239
-
240
- Above is an example of a constant violation entry in `package_todo.yml`.
241
-
242
- * `components/merchant` - package where the constant violation is found
243
- * `::Checkouts::Core::CheckoutId` - violated constant in question
244
- * `dependency` - type of violation, typically dependency
245
- * `components/merchant/app/public/merchant/generate_order.rb` - path to the file containing the violated constant
246
-
247
- Violations exist within the package that makes a violating reference.
248
-
249
- # Loading Extensions
250
-
251
- You can optionally specify ruby files that you'd like to be loaded with `packwerk` by specifying a `require` directive in `packwerk.yml`:
252
- ```yml
253
- require:
254
- - ./path/to/file.rb
255
- - my_gem
256
- ```
257
-
258
- `packwerk` will directly call `require` with these paths.
259
- You can prefix local files with a dot to define them relative to `packwerk.yml`, or you can use absolute paths.
260
- You can also reference the name of a gem.
261
-
262
- ## Examples
263
-
264
- ### Custom Offense Formatter
265
-
266
- 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.
267
-
268
- 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:
269
- ```ruby
270
- # ./path/to/file.rb
271
- class MyOffensesFormatter
272
- include Packwerk::OffensesFormatter
273
- # implement the `OffensesFormatter` interface
274
-
275
- def identifier
276
- 'my_offenses_formatter'
277
- end
278
- end
279
- ```
280
-
281
- Then in `packwerk.yml`, you can set the `formatter` to the identifier for your class:
282
- ```yml
283
- offenses_formatter: my_offenses_formatter
284
- ```
285
-
286
- You can also pass in a formatter on the command line:
287
- ```
288
- bin/packwerk check --offenses-formatter=my_offenses_formatter
289
- ```
290
-
291
- ### Custom Checkers
292
-
293
- Packwerk ships with a way to analyze dependencies and also supports custom checkers from extension gems.
294
-
295
- 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`.
296
-
297
- 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:
298
-
299
- ```ruby
300
- # ./path/to/file.rb
301
- class MyChecker
302
- include Packwerk::Checker
303
- # implement the `Checker` interface
304
-
305
- sig { override.returns(String) }
306
- def violation_type
307
- 'my_custom_violation_type'
308
- end
309
-
310
- sig { override.params(listed_offense: ReferenceOffense).returns(T::Boolean) }
311
- def strict_mode_violation?(listed_offense)
312
- # This will allow "strict mode" to be supported in your checker
313
- referencing_package = listed_offense.reference.package
314
- referencing_package.config["enforce_custom"] == "strict"
315
- end
316
-
317
- sig { override.params(reference: Reference).returns(T::Boolean) }
318
- def invalid_reference?(reference)
319
- # your logic here
320
- end
321
-
322
- sig { override.params(reference: Reference).returns(String) }
323
- def message(reference)
324
- # your message here
325
- end
326
- end
327
- ```
328
-
329
- Then, in the `require` directive described above, you'll want to tell `packwerk` about it:
330
-
331
- ```yml
332
- require:
333
- - ./path/to/file.rb
334
- ```
335
-
336
- ### Custom Validators
337
-
338
- 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.
339
-
340
- 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:
341
-
342
- ```ruby
343
- # ./path/to/file.rb
344
- class MyValidator
345
- include Packwerk::Validator
346
- # implement the `Validator` interface
347
-
348
- sig { override.returns(T::Array[String]) }
349
- def permitted_keys
350
- ['enforce_my_custom_checker']
351
- end
352
-
353
- sig { override.params(package_set: PackageSet, configuration: Configuration).returns(ApplicationValidator::Result) }
354
- def call(package_set, configuration)
355
- # your logic here
356
- end
357
- end
358
- ```
359
-
360
- Then, in the `require` directive described above, you'll want to tell `packwerk` about it:
361
-
362
- ```yml
363
- require:
364
- - ./path/to/file.rb
365
- ```
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,58 +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
-
54
- # For ERB parsing
55
- spec.add_dependency("better_html")
56
-
57
- spec.add_development_dependency("railties")
58
- end