Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# This file strictly follows the rules defined in the Ruby style guide:
# http://shopify.github.io/ruby-style-guide/

require: 'rubocop-sorbet'
plugins:
- rubocop-sorbet

inherit_gem:
rubocop-shopify: rubocop.yml
Expand All @@ -17,8 +18,8 @@ Layout/LeadingCommentSpace:
AllowRBSInlineAnnotation: true

Layout/LineLength:
Enabled: true
Max: 120
AllowedPatterns: ['\A\s*#:']

Sorbet:
Enabled: true
Expand Down
6 changes: 5 additions & 1 deletion lib/spoom/context/file_system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ def list
glob("*")
end

#: (?allow_extensions: Array[String], ?allow_mime_types: Array[String], ?exclude_patterns: Array[String]) -> Array[String]
#: (
#| ?allow_extensions: Array[String],
#| ?allow_mime_types: Array[String],
#| ?exclude_patterns: Array[String]
#| ) -> Array[String]
def collect_files(allow_extensions: [], allow_mime_types: [], exclude_patterns: [])
collector = FileCollector.new(
allow_extensions: allow_extensions,
Expand Down
7 changes: 6 additions & 1 deletion lib/spoom/coverage/d3/circle_map.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,12 @@ def script
end

class Sigils < CircleMap
#: (String id, FileTree file_tree, Hash[FileTree::Node, String?] nodes_strictnesses, Hash[FileTree::Node, Float] nodes_scores) -> void
#: (
#| String id,
#| FileTree file_tree,
#| Hash[FileTree::Node, String?] nodes_strictnesses,
#| Hash[FileTree::Node, Float] nodes_scores
#| ) -> void
def initialize(id, file_tree, nodes_strictnesses, nodes_scores)
@nodes_strictnesses = nodes_strictnesses
@nodes_scores = nodes_scores
Expand Down
18 changes: 16 additions & 2 deletions lib/spoom/coverage/report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,12 @@ def pie_sigs
end

class Map < Card
#: (file_tree: FileTree, nodes_strictnesses: Hash[FileTree::Node, String?], nodes_strictness_scores: Hash[FileTree::Node, Float], ?title: String) -> void
#: (
#| file_tree: FileTree,
#| nodes_strictnesses: Hash[FileTree::Node, String?],
#| nodes_strictness_scores: Hash[FileTree::Node, Float],
#| ?title: String
#| ) -> void
def initialize(file_tree:, nodes_strictnesses:, nodes_strictness_scores:, title: "Strictness Map")
super(
title: title,
Expand Down Expand Up @@ -222,7 +227,16 @@ def erb
end

class Report < Page
#: (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
#: (
#| 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
def initialize(
project_name:,
palette:,
Expand Down
17 changes: 15 additions & 2 deletions lib/spoom/model/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,13 @@ class Class < Namespace
#: String?
attr_accessor :superclass_name

#: (Symbol symbol, owner: Namespace?, location: Location, ?superclass_name: String?, ?comments: Array[Comment]) -> void
#: (
#| Symbol symbol,
#| owner: Namespace?,
#| location: Location,
#| ?superclass_name: String?,
#| ?comments: Array[Comment]
#| ) -> void
def initialize(symbol, owner:, location:, superclass_name: nil, comments: [])
super(symbol, owner: owner, location: location, comments: comments)

Expand Down Expand Up @@ -160,7 +166,14 @@ class Property < SymbolDef
#: Array[Sig]
attr_reader :sigs

#: (Symbol symbol, owner: Namespace?, location: Location, visibility: Visibility, ?sigs: Array[Sig], ?comments: Array[Comment]) -> void
#: (
#| Symbol symbol,
#| owner: Namespace?,
#| location: Location,
#| visibility: Visibility,
#| ?sigs: Array[Sig],
#| ?comments: Array[Comment]
#| ) -> void
def initialize(symbol, owner:, location:, visibility:, sigs: [], comments: [])
super(symbol, owner: owner, location: location, comments: comments)

Expand Down
7 changes: 6 additions & 1 deletion lib/spoom/rbs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ def class_annotations
def method_annotations
@annotations.select do |annotation|
case annotation.string
when "@abstract", "@final", "@override", "@override(allow_incompatible: true)", "@overridable", "@without_runtime"
when "@abstract",
"@final",
"@override",
"@override(allow_incompatible: true)",
"@overridable",
"@without_runtime"
true
else
false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,10 @@ def maybe_translate_assertion(node)
Prism::ClassVariableWriteNode, Prism::ClassVariableAndWriteNode, Prism::ClassVariableOperatorWriteNode, Prism::ClassVariableOrWriteNode,
Prism::ConstantWriteNode, Prism::ConstantAndWriteNode, Prism::ConstantOperatorWriteNode, Prism::ConstantOrWriteNode,
Prism::ConstantPathWriteNode, Prism::ConstantPathAndWriteNode, Prism::ConstantPathOperatorWriteNode, Prism::ConstantPathOrWriteNode,
Prism::GlobalVariableWriteNode, Prism::GlobalVariableAndWriteNode, Prism::GlobalVariableOperatorWriteNode, Prism::GlobalVariableOrWriteNode,
Prism::InstanceVariableWriteNode, Prism::InstanceVariableAndWriteNode, Prism::InstanceVariableOperatorWriteNode, Prism::InstanceVariableOrWriteNode,
Prism::GlobalVariableWriteNode, Prism::GlobalVariableAndWriteNode,
Prism::GlobalVariableOperatorWriteNode, Prism::GlobalVariableOrWriteNode,
Prism::InstanceVariableWriteNode, Prism::InstanceVariableAndWriteNode,
Prism::InstanceVariableOperatorWriteNode, Prism::InstanceVariableOrWriteNode,
Prism::LocalVariableWriteNode, Prism::LocalVariableAndWriteNode, Prism::LocalVariableOperatorWriteNode, Prism::LocalVariableOrWriteNode,
Prism::CallAndWriteNode, Prism::CallOperatorWriteNode, Prism::CallOrWriteNode
node.value
Expand Down
5 changes: 4 additions & 1 deletion lib/spoom/sorbet/translate/sorbet_sigs_to_rbs_comments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,10 @@ def apply_class_annotation(parent, node)

arg = body.body.first #: as Prism::Node
srb_type = RBI::Type.parse_node(arg)
@rewriter << Source::Insert.new(parent.location.start_offset, "# @requires_ancestor: #{srb_type.rbs_string}\n#{indent}")
@rewriter << Source::Insert.new(
parent.location.start_offset,
"# @requires_ancestor: #{srb_type.rbs_string}\n#{indent}",
)
end

from = adjust_to_line_start(node.location.start_offset)
Expand Down
6 changes: 4 additions & 2 deletions lib/spoom/source/rewriter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ def initialize(from, to, text)
# @override
#: (Array[Integer]) -> void
def apply(bytes)
raise PositionError, "Position is out of bounds" if from < 0 || to < 0 || from > bytes.size || to > bytes.size || from > to
raise PositionError,
"Position is out of bounds" if from < 0 || to < 0 || from > bytes.size || to > bytes.size || from > to

bytes[from..to] = *text.bytes
end
Expand Down Expand Up @@ -125,7 +126,8 @@ def initialize(from, to)
# @override
#: (Array[untyped]) -> void
def apply(bytes)
raise PositionError, "Position is out of bounds" if from < 0 || to < 0 || from > bytes.size || to > bytes.size || from > to
raise PositionError,
"Position is out of bounds" if from < 0 || to < 0 || from > bytes.size || to > bytes.size || from > to

bytes[from..to] = "".bytes
end
Expand Down
10 changes: 9 additions & 1 deletion test/spoom/cli/srb/assertions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,15 @@ def test_translate_from_rbi_to_rbs_with_options

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

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")
result = @project.spoom(<<~CMD)
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
CMD

assert_empty(result.err)
assert(result.status)
Expand Down
7 changes: 6 additions & 1 deletion test/spoom/file_collector_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,12 @@ def test_collect_files_with_allowed_mime_types

private

#: (Context context, ?allow_extensions: Array[String], ?allow_mime_types: Array[String], ?exclude_patterns: Array[String]) -> Array[String]
#: (
#| Context context,
#| ?allow_extensions: Array[String],
#| ?allow_mime_types: Array[String],
#| ?exclude_patterns: Array[String]
#| ) -> Array[String]
def collect_files(context, allow_extensions: [], allow_mime_types: [], exclude_patterns: [])
# Since we work in the context directory, we need to prefix the patterns with it
exclude_patterns = exclude_patterns.map { |p| File.join(context.absolute_path, p) }
Expand Down