Skip to content

Commit f081cca

Browse files
authored
Drop sorbet-runtime dependency by migrating to RBS comment annotations (#68)
* Update gem rbis * Modernize Sorbet tooling and pin rubocop-sorbet for new T.let cops Bump sorbet, sorbet-runtime, tapioca, spoom, rbi, and rbs to current versions and regenerate the gem RBIs to match. Pin rubocop-sorbet to Shopify/rubocop-sorbet@7b7d3cb (post-#367 and post-#372) so the not-yet-released Sorbet/RedundantTLetForLiteral and Sorbet/RedundantTLet cops are available. * Remove redundant T.let on literals via Sorbet cops Apply Sorbet/RedundantTLetForLiteral and Sorbet/RedundantTLet autocorrections. Sorbet infers the type of literal constants automatically, so the explicit T.let wrappers were redundant. * Migrate type annotations to RBS comments and drop sorbet-runtime Replace Sorbet's runtime DSL with inline RBS comment annotations so the gem no longer depends on sorbet-runtime at runtime, matching upstream packwerk (Shopify/packwerk#455). - Enable --parser=prism and --enable-experimental-rbs-comments in sorbet/config - Translate all sig blocks to #: RBS comments (via spoom) - Convert the T::Struct Package classes to plain classes with RBS-annotated attr_readers and keyword initializers - Replace T.let / T.must / extend T::Sig with inline RBS annotations - Drop require 'sorbet-runtime' and the sorbet-runtime gem dependency * Trim rubocop config for the RBS migration - Allow RBS inline annotation comments (Layout/LeadingCommentSpace) - Set TargetRubyVersion to 3.2 (matches required_ruby_version), fixing Lint/RedundantRequireStatement on the binstubs - Remove disabled-cop entries that no longer have any violations, including Style/TrivialAccessors (its Sorbet-sig rationale is moot now that RBS makes annotated attr_readers clean) * Bump minimum Ruby version to 3.3 The modernized Sorbet toolchain pulls in rbi 0.3.12, which requires Ruby >= 3.3. Raise required_ruby_version and TargetRubyVersion to match.
1 parent cbad747 commit f081cca

94 files changed

Lines changed: 78962 additions & 120624 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.rubocop.yml

Lines changed: 4 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,16 @@ plugins:
1616
AllCops:
1717
SuggestExtensions: false
1818
NewCops: enable
19+
TargetRubyVersion: 3.3
1920
Exclude:
2021
- vendor/bundle/**/**
2122

2223
Metrics/ParameterLists:
2324
Enabled: false
2425

25-
# This cop is annoying with typed configuration
26-
Style/TrivialAccessors:
27-
Enabled: false
26+
# Allow RBS inline type annotation comments (`#:` and `#|`).
27+
Layout/LeadingCommentSpace:
28+
AllowRBSInlineAnnotation: true
2829

2930
# This rubocop is annoying when we use interfaces a lot
3031
Lint/UnusedMethodArgument:
@@ -33,9 +34,6 @@ Lint/UnusedMethodArgument:
3334
Gemspec/RequireMFA:
3435
Enabled: false
3536

36-
Lint/DuplicateBranch:
37-
Enabled: false
38-
3937
# If is sometimes easier to think about than unless sometimes
4038
Style/NegatedIf:
4139
Enabled: false
@@ -44,31 +42,18 @@ Style/NegatedIf:
4442
Style/FrozenStringLiteralComment:
4543
Enabled: false
4644

47-
# It's nice to be able to read the condition first before reading the code within the condition
48-
Style/GuardClause:
49-
Enabled: false
50-
5145
#
5246
# Leaving length metrics to human judgment for now
5347
#
54-
Metrics/ModuleLength:
55-
Enabled: false
56-
5748
Layout/LineLength:
5849
Enabled: false
5950

60-
Metrics/BlockLength:
61-
Enabled: false
62-
6351
Metrics/MethodLength:
6452
Enabled: false
6553

6654
Metrics/AbcSize:
6755
Enabled: false
6856

69-
Metrics/ClassLength:
70-
Enabled: false
71-
7257
# This doesn't feel useful
7358
Metrics/CyclomaticComplexity:
7459
Enabled: false
@@ -89,26 +74,6 @@ Style/ConditionalAssignment:
8974
Style/Documentation:
9075
Enabled: false
9176

92-
# Sometimes we leave comments in empty else statements intentionally
93-
Style/EmptyElse:
94-
Enabled: false
95-
96-
# Sometimes we want to more explicitly list out a condition
97-
Style/RedundantCondition:
98-
Enabled: false
99-
100-
# This leads to code that is not very readable at times (very long lines)
101-
Layout/MultilineMethodCallIndentation:
102-
Enabled: false
103-
104-
# Blocks across lines are okay sometimes
105-
Style/BlockDelimiters:
106-
Enabled: false
107-
108-
# Sometimes we like methods like `get_packages`
109-
Naming/AccessorMethodName:
110-
Enabled: false
111-
11277
# This leads to code that is not very readable at times (very long lines)
11378
Layout/FirstArgumentIndentation:
11479
Enabled: false
@@ -117,15 +82,6 @@ Layout/FirstArgumentIndentation:
11782
Layout/ArgumentAlignment:
11883
Enabled: false
11984

120-
Style/AccessorGrouping:
121-
Enabled: false
122-
123-
Style/NumericPredicate:
124-
Enabled: false
125-
126-
Layout/BlockEndNewline:
127-
Enabled: false
128-
12985
Naming/FileName:
13086
Exclude:
13187
- lib/packwerk-extensions.rb

Gemfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@
33
source 'https://rubygems.org'
44

55
gemspec
6+
7+
# Pinned to main for the not-yet-released `Sorbet/RedundantTLet` and
8+
# `Sorbet/RedundantTLetForLiteral` cops (see Shopify/rubocop-sorbet#372 and #367).
9+
gem 'rubocop-sorbet', github: 'Shopify/rubocop-sorbet', ref: '7b7d3cb5a41cee8207b3cd00c21f5ef43f7140fd'

Gemfile.lock

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
1+
GIT
2+
remote: https://github.com/Shopify/rubocop-sorbet.git
3+
revision: 7b7d3cb5a41cee8207b3cd00c21f5ef43f7140fd
4+
ref: 7b7d3cb5a41cee8207b3cd00c21f5ef43f7140fd
5+
specs:
6+
rubocop-sorbet (0.12.0)
7+
lint_roller
8+
rubocop (>= 1.75.2)
9+
110
PATH
211
remote: .
312
specs:
413
packwerk-extensions (0.3.0)
514
packwerk (>= 3)
615
railties (>= 6.0.0)
7-
sorbet-runtime
816
zeitwerk
917

1018
GEM
@@ -106,7 +114,7 @@ GEM
106114
prism (>= 0.25.0)
107115
sorbet-runtime (>= 0.5.9914)
108116
zeitwerk (>= 2.6.1)
109-
parallel (1.27.0)
117+
parallel (1.28.0)
110118
parser (3.3.10.2)
111119
ast (~> 2.4.1)
112120
racc
@@ -149,12 +157,12 @@ GEM
149157
zeitwerk (~> 2.6)
150158
rainbow (3.1.1)
151159
rake (13.3.1)
152-
rbi (0.3.9)
160+
rbi (0.3.12)
153161
prism (~> 1.0)
154-
rbs (>= 3.4.4)
155-
rbs (4.0.0.dev.5)
162+
rbs (>= 4.0.1)
163+
rbs (4.1.0.pre.1)
156164
logger
157-
prism (>= 1.3.0)
165+
prism (>= 1.6.0)
158166
tsort
159167
rdoc (7.2.0)
160168
erb
@@ -163,7 +171,7 @@ GEM
163171
regexp_parser (2.11.3)
164172
reline (0.6.3)
165173
io-console (~> 0.5)
166-
require-hooks (0.2.3)
174+
require-hooks (0.4.0)
167175
rexml (3.4.4)
168176
rubocop (1.85.1)
169177
json (~> 2.3)
@@ -198,41 +206,42 @@ GEM
198206
rubocop-rspec (3.9.0)
199207
lint_roller (~> 1.1)
200208
rubocop (~> 1.81)
201-
rubocop-sorbet (0.12.0)
202-
lint_roller
203-
rubocop (>= 1.75.2)
204209
ruby-progressbar (1.13.0)
205210
ruby2_keywords (0.0.5)
211+
rubydex (0.2.5-arm64-darwin)
212+
rubydex (0.2.5-x86_64-darwin)
213+
rubydex (0.2.5-x86_64-linux)
206214
securerandom (0.4.1)
207215
smart_properties (1.17.0)
208-
sorbet (0.6.12992)
209-
sorbet-static (= 0.6.12992)
210-
sorbet-runtime (0.6.12992)
211-
sorbet-static (0.6.12992-universal-darwin)
212-
sorbet-static (0.6.12992-x86_64-linux)
213-
sorbet-static-and-runtime (0.6.12992)
214-
sorbet (= 0.6.12992)
215-
sorbet-runtime (= 0.6.12992)
216-
spoom (1.7.11)
216+
sorbet (0.6.13258)
217+
sorbet-static (= 0.6.13258)
218+
sorbet-runtime (0.6.13258)
219+
sorbet-static (0.6.13258-universal-darwin)
220+
sorbet-static (0.6.13258-x86_64-linux)
221+
sorbet-static-and-runtime (0.6.13258)
222+
sorbet (= 0.6.13258)
223+
sorbet-runtime (= 0.6.13258)
224+
spoom (1.7.16)
217225
erubi (>= 1.10.0)
218226
prism (>= 0.28.0)
219227
rbi (>= 0.3.3)
220-
rbs (>= 4.0.0.dev.4)
228+
rbs (>= 4.0.0.dev.5)
221229
rexml (>= 3.2.6)
222230
sorbet-static-and-runtime (>= 0.5.10187)
223231
thor (>= 0.19.2)
224232
stringio (3.2.0)
225-
tapioca (0.17.10)
233+
tapioca (0.19.1)
226234
benchmark
227235
bundler (>= 2.2.25)
228236
netrc (>= 0.11.0)
229237
parallel (>= 1.21.0)
230238
rbi (>= 0.3.7)
231239
require-hooks (>= 0.2.2)
232-
sorbet-static-and-runtime (>= 0.5.11087)
240+
rubydex (>= 0.1.0.beta10)
241+
sorbet-static-and-runtime (>= 0.6.12698)
233242
spoom (>= 1.7.9)
234243
thor (>= 1.2.0)
235-
yard-sorbet
244+
tsort
236245
thor (1.5.0)
237246
tsort (0.2.0)
238247
tzinfo (2.0.6)
@@ -242,10 +251,6 @@ GEM
242251
unicode-emoji (4.2.0)
243252
uri (1.1.1)
244253
useragent (0.16.11)
245-
yard (0.9.38)
246-
yard-sorbet (0.9.0)
247-
sorbet-runtime
248-
yard
249254
zeitwerk (2.7.5)
250255

251256
PLATFORMS
@@ -261,6 +266,7 @@ DEPENDENCIES
261266
rake
262267
rubocop
263268
rubocop-gusto
269+
rubocop-sorbet!
264270
sorbet
265271
sorbet-static
266272
tapioca

lib/packwerk-extensions.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# typed: strict
22
# frozen_string_literal: true
33

4-
require 'sorbet-runtime'
54
require 'packwerk'
65

76
require 'packwerk/privacy/checker'

lib/packwerk/folder_privacy/checker.rb

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,18 @@
77
module Packwerk
88
module FolderPrivacy
99
class Checker
10-
extend T::Sig
1110
include Packwerk::Checker
1211

13-
VIOLATION_TYPE = T.let('folder_privacy', String)
12+
VIOLATION_TYPE = 'folder_privacy'
1413

15-
sig { override.returns(String) }
14+
# @override
15+
#: -> String
1616
def violation_type
1717
VIOLATION_TYPE
1818
end
1919

20-
sig do
21-
override
22-
.params(reference: Packwerk::Reference)
23-
.returns(T::Boolean)
24-
end
20+
# @override
21+
#: (Packwerk::Reference reference) -> bool
2522
def invalid_reference?(reference)
2623
referencing_package = reference.package
2724
referenced_package = reference.constant.package
@@ -41,21 +38,15 @@ def invalid_reference?(reference)
4138
true
4239
end
4340

44-
sig do
45-
override
46-
.params(listed_offense: Packwerk::ReferenceOffense)
47-
.returns(T::Boolean)
48-
end
41+
# @override
42+
#: (Packwerk::ReferenceOffense listed_offense) -> bool
4943
def strict_mode_violation?(listed_offense)
5044
publishing_package = listed_offense.reference.constant.package
5145
publishing_package.config['enforce_folder_privacy'] == 'strict'
5246
end
5347

54-
sig do
55-
override
56-
.params(reference: Packwerk::Reference)
57-
.returns(String)
58-
end
48+
# @override
49+
#: (Packwerk::Reference reference) -> String
5950
def message(reference)
6051
source_desc = "'#{reference.package}'"
6152

@@ -71,15 +62,12 @@ def message(reference)
7162

7263
private
7364

74-
sig do
75-
params(visibility_option: T.nilable(T.any(T::Boolean, String)))
76-
.returns(T::Boolean)
77-
end
65+
#: ((bool | String)? visibility_option) -> bool
7866
def enforcement_disabled?(visibility_option)
7967
[false, nil].include?(visibility_option)
8068
end
8169

82-
sig { params(reference: Reference).returns(String) }
70+
#: (Reference reference) -> String
8371
def standard_help_message(reference)
8472
standard_message = <<~MESSAGE.chomp
8573
Inference details: this is a reference to #{reference.constant.name} which seems to be defined in #{reference.constant.location}.

lib/packwerk/folder_privacy/package.rb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@
33

44
module Packwerk
55
module FolderPrivacy
6-
class Package < T::Struct
7-
extend T::Sig
6+
class Package
7+
#: (bool | String)?
8+
attr_reader :enforce_folder_privacy
89

9-
const :enforce_folder_privacy, T.nilable(T.any(T::Boolean, String))
10+
#: (enforce_folder_privacy: (bool | String)?) -> void
11+
def initialize(enforce_folder_privacy:)
12+
@enforce_folder_privacy = enforce_folder_privacy
13+
end
1014

1115
class << self
12-
extend T::Sig
13-
14-
sig { params(package: ::Packwerk::Package).returns(Package) }
16+
#: (::Packwerk::Package package) -> Package
1517
def from(package)
1618
Package.new(
1719
enforce_folder_privacy: package.config['enforce_folder_privacy']

lib/packwerk/folder_privacy/validator.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
module Packwerk
55
module FolderPrivacy
66
class Validator
7-
extend T::Sig
87
include Packwerk::Validator
98

109
Result = Packwerk::Validator::Result
1110

12-
sig { override.params(package_set: PackageSet, configuration: Configuration).returns(Result) }
11+
# @override
12+
#: (PackageSet package_set, Configuration configuration) -> Result
1313
def call(package_set, configuration)
14-
results = T.let([], T::Array[Result])
14+
results = [] #: Array[Result]
1515

1616
package_manifests_settings_for(configuration, 'enforce_folder_privacy').each do |config, setting|
1717
next if setting.nil?
@@ -27,7 +27,8 @@ def call(package_set, configuration)
2727
merge_results(results, separator: "\n---\n")
2828
end
2929

30-
sig { override.returns(T::Array[String]) }
30+
# @override
31+
#: -> Array[String]
3132
def permitted_keys
3233
%w(enforce_folder_privacy)
3334
end

0 commit comments

Comments
 (0)