Skip to content

Commit 2fd878b

Browse files
authored
Merge pull request #805 from Shopify/at-rubocop-line-length
Migrate long RBS signature comments to multiline sigs
2 parents dc6aedb + f636364 commit 2fd878b

File tree

11 files changed

+78
-16
lines changed

11 files changed

+78
-16
lines changed

.rubocop.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# This file strictly follows the rules defined in the Ruby style guide:
22
# http://shopify.github.io/ruby-style-guide/
33

4-
require: 'rubocop-sorbet'
4+
plugins:
5+
- rubocop-sorbet
56

67
inherit_gem:
78
rubocop-shopify: rubocop.yml
@@ -17,8 +18,8 @@ Layout/LeadingCommentSpace:
1718
AllowRBSInlineAnnotation: true
1819

1920
Layout/LineLength:
21+
Enabled: true
2022
Max: 120
21-
AllowedPatterns: ['\A\s*#:']
2223

2324
Sorbet:
2425
Enabled: true

lib/spoom/context/file_system.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ def list
3939
glob("*")
4040
end
4141

42-
#: (?allow_extensions: Array[String], ?allow_mime_types: Array[String], ?exclude_patterns: Array[String]) -> Array[String]
42+
#: (
43+
#| ?allow_extensions: Array[String],
44+
#| ?allow_mime_types: Array[String],
45+
#| ?exclude_patterns: Array[String]
46+
#| ) -> Array[String]
4347
def collect_files(allow_extensions: [], allow_mime_types: [], exclude_patterns: [])
4448
collector = FileCollector.new(
4549
allow_extensions: allow_extensions,

lib/spoom/coverage/d3/circle_map.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,12 @@ def script
145145
end
146146

147147
class Sigils < CircleMap
148-
#: (String id, FileTree file_tree, Hash[FileTree::Node, String?] nodes_strictnesses, Hash[FileTree::Node, Float] nodes_scores) -> void
148+
#: (
149+
#| String id,
150+
#| FileTree file_tree,
151+
#| Hash[FileTree::Node, String?] nodes_strictnesses,
152+
#| Hash[FileTree::Node, Float] nodes_scores
153+
#| ) -> void
149154
def initialize(id, file_tree, nodes_strictnesses, nodes_scores)
150155
@nodes_strictnesses = nodes_strictnesses
151156
@nodes_scores = nodes_scores

lib/spoom/coverage/report.rb

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,12 @@ def pie_sigs
138138
end
139139

140140
class Map < Card
141-
#: (file_tree: FileTree, nodes_strictnesses: Hash[FileTree::Node, String?], nodes_strictness_scores: Hash[FileTree::Node, Float], ?title: String) -> void
141+
#: (
142+
#| file_tree: FileTree,
143+
#| nodes_strictnesses: Hash[FileTree::Node, String?],
144+
#| nodes_strictness_scores: Hash[FileTree::Node, Float],
145+
#| ?title: String
146+
#| ) -> void
142147
def initialize(file_tree:, nodes_strictnesses:, nodes_strictness_scores:, title: "Strictness Map")
143148
super(
144149
title: title,
@@ -222,7 +227,16 @@ def erb
222227
end
223228

224229
class Report < Page
225-
#: (project_name: String, palette: D3::ColorPalette, snapshots: Array[Snapshot], file_tree: FileTree, nodes_strictnesses: Hash[FileTree::Node, String?], nodes_strictness_scores: Hash[FileTree::Node, Float], ?sorbet_intro_commit: String?, ?sorbet_intro_date: Time?) -> void
230+
#: (
231+
#| project_name: String,
232+
#| palette: D3::ColorPalette,
233+
#| snapshots: Array[Snapshot],
234+
#| file_tree: FileTree,
235+
#| nodes_strictnesses: Hash[FileTree::Node, String?],
236+
#| nodes_strictness_scores: Hash[FileTree::Node, Float],
237+
#| ?sorbet_intro_commit: String?,
238+
#| ?sorbet_intro_date: Time?
239+
#| ) -> void
226240
def initialize(
227241
project_name:,
228242
palette:,

lib/spoom/model/model.rb

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,13 @@ class Class < Namespace
129129
#: String?
130130
attr_accessor :superclass_name
131131

132-
#: (Symbol symbol, owner: Namespace?, location: Location, ?superclass_name: String?, ?comments: Array[Comment]) -> void
132+
#: (
133+
#| Symbol symbol,
134+
#| owner: Namespace?,
135+
#| location: Location,
136+
#| ?superclass_name: String?,
137+
#| ?comments: Array[Comment]
138+
#| ) -> void
133139
def initialize(symbol, owner:, location:, superclass_name: nil, comments: [])
134140
super(symbol, owner: owner, location: location, comments: comments)
135141

@@ -160,7 +166,14 @@ class Property < SymbolDef
160166
#: Array[Sig]
161167
attr_reader :sigs
162168

163-
#: (Symbol symbol, owner: Namespace?, location: Location, visibility: Visibility, ?sigs: Array[Sig], ?comments: Array[Comment]) -> void
169+
#: (
170+
#| Symbol symbol,
171+
#| owner: Namespace?,
172+
#| location: Location,
173+
#| visibility: Visibility,
174+
#| ?sigs: Array[Sig],
175+
#| ?comments: Array[Comment]
176+
#| ) -> void
164177
def initialize(symbol, owner:, location:, visibility:, sigs: [], comments: [])
165178
super(symbol, owner: owner, location: location, comments: comments)
166179

lib/spoom/rbs.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,12 @@ def class_annotations
3939
def method_annotations
4040
@annotations.select do |annotation|
4141
case annotation.string
42-
when "@abstract", "@final", "@override", "@override(allow_incompatible: true)", "@overridable", "@without_runtime"
42+
when "@abstract",
43+
"@final",
44+
"@override",
45+
"@override(allow_incompatible: true)",
46+
"@overridable",
47+
"@without_runtime"
4348
true
4449
else
4550
false

lib/spoom/sorbet/translate/sorbet_assertions_to_rbs_comments.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,10 @@ def maybe_translate_assertion(node)
7474
Prism::ClassVariableWriteNode, Prism::ClassVariableAndWriteNode, Prism::ClassVariableOperatorWriteNode, Prism::ClassVariableOrWriteNode,
7575
Prism::ConstantWriteNode, Prism::ConstantAndWriteNode, Prism::ConstantOperatorWriteNode, Prism::ConstantOrWriteNode,
7676
Prism::ConstantPathWriteNode, Prism::ConstantPathAndWriteNode, Prism::ConstantPathOperatorWriteNode, Prism::ConstantPathOrWriteNode,
77-
Prism::GlobalVariableWriteNode, Prism::GlobalVariableAndWriteNode, Prism::GlobalVariableOperatorWriteNode, Prism::GlobalVariableOrWriteNode,
78-
Prism::InstanceVariableWriteNode, Prism::InstanceVariableAndWriteNode, Prism::InstanceVariableOperatorWriteNode, Prism::InstanceVariableOrWriteNode,
77+
Prism::GlobalVariableWriteNode, Prism::GlobalVariableAndWriteNode,
78+
Prism::GlobalVariableOperatorWriteNode, Prism::GlobalVariableOrWriteNode,
79+
Prism::InstanceVariableWriteNode, Prism::InstanceVariableAndWriteNode,
80+
Prism::InstanceVariableOperatorWriteNode, Prism::InstanceVariableOrWriteNode,
7981
Prism::LocalVariableWriteNode, Prism::LocalVariableAndWriteNode, Prism::LocalVariableOperatorWriteNode, Prism::LocalVariableOrWriteNode,
8082
Prism::CallAndWriteNode, Prism::CallOperatorWriteNode, Prism::CallOrWriteNode
8183
node.value

lib/spoom/sorbet/translate/sorbet_sigs_to_rbs_comments.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,10 @@ def apply_class_annotation(parent, node)
260260

261261
arg = body.body.first #: as Prism::Node
262262
srb_type = RBI::Type.parse_node(arg)
263-
@rewriter << Source::Insert.new(parent.location.start_offset, "# @requires_ancestor: #{srb_type.rbs_string}\n#{indent}")
263+
@rewriter << Source::Insert.new(
264+
parent.location.start_offset,
265+
"# @requires_ancestor: #{srb_type.rbs_string}\n#{indent}",
266+
)
264267
end
265268

266269
from = adjust_to_line_start(node.location.start_offset)

lib/spoom/source/rewriter.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ def initialize(from, to, text)
9292
# @override
9393
#: (Array[Integer]) -> void
9494
def apply(bytes)
95-
raise PositionError, "Position is out of bounds" if from < 0 || to < 0 || from > bytes.size || to > bytes.size || from > to
95+
raise PositionError,
96+
"Position is out of bounds" if from < 0 || to < 0 || from > bytes.size || to > bytes.size || from > to
9697

9798
bytes[from..to] = *text.bytes
9899
end
@@ -125,7 +126,8 @@ def initialize(from, to)
125126
# @override
126127
#: (Array[untyped]) -> void
127128
def apply(bytes)
128-
raise PositionError, "Position is out of bounds" if from < 0 || to < 0 || from > bytes.size || to > bytes.size || from > to
129+
raise PositionError,
130+
"Position is out of bounds" if from < 0 || to < 0 || from > bytes.size || to > bytes.size || from > to
129131

130132
bytes[from..to] = "".bytes
131133
end

test/spoom/cli/srb/assertions_test.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,15 @@ def test_translate_from_rbi_to_rbs_with_options
4242

4343
@project.write!("file.rb", contents)
4444

45-
result = @project.spoom("srb assertions translate --no-color --no-translate-t-let --no-translate-t-cast --no-translate-t-bind --no-translate-t-must --no-translate-t-unsafe")
45+
result = @project.spoom(<<~CMD)
46+
srb assertions translate \
47+
--no-color \
48+
--no-translate-t-let \
49+
--no-translate-t-cast \
50+
--no-translate-t-bind \
51+
--no-translate-t-must \
52+
--no-translate-t-unsafe
53+
CMD
4654

4755
assert_empty(result.err)
4856
assert(result.status)

0 commit comments

Comments
 (0)