Skip to content

Commit

Permalink
Merge pull request #393 from Shopify/at-rbs-spaces
Browse files Browse the repository at this point in the history
Handle spaces in types during RBS translation
  • Loading branch information
Morriar authored Jan 15, 2025
2 parents 66af789 + 89afbcf commit 7a93edf
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/rbi/rbs_printer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ def visit(node)

sig { params(type: Type::Simple).void }
def visit_simple(type)
@string << translate_t_type(type.name)
@string << translate_t_type(type.name.gsub(/\s/, ""))
end

sig { params(type: Type::Boolean).void }
Expand All @@ -852,7 +852,7 @@ def visit_boolean(type)

sig { params(type: Type::Generic).void }
def visit_generic(type)
@string << translate_t_type(type.name)
@string << translate_t_type(type.name.gsub(/\s/, ""))
@string << "["
type.params.each_with_index do |arg, index|
visit(arg)
Expand Down
10 changes: 10 additions & 0 deletions test/rbi/parser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,16 @@ def test_parse_constants
assert_equal(rbi, tree.string)
end

def test_parse_constants_with_newlines
rbi = <<~RBI
sig { returns(Foo::
Bar) }
RBI

tree = parse_rbi(rbi)
assert_equal(rbi, tree.string)
end

def test_parse_attributes
rbi = <<~RBI
attr_reader :a
Expand Down
12 changes: 12 additions & 0 deletions test/rbi/rbs_printer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,18 @@ def test_print_attr_sig
RBI
end

def test_print_signature_with_newlines
rbi = parse_rbi(<<~RBI)
sig { returns(T.class_of(Foo::
Bar)) }
def foo; end
RBI

assert_equal(<<~RBI, rbi.rbs_string)
def foo: -> singleton(Foo::Bar)
RBI
end

def test_print_methods_without_signature
rbi = parse_rbi(<<~RBI)
def foo; end
Expand Down

0 comments on commit 7a93edf

Please sign in to comment.