ruby-syntax-tree / syntax_tree

Interact with the Ruby syntax tree

Home Page:https://ruby-syntax-tree.github.io/syntax_tree/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Hash literal without braces has invalid syntax after formatting

naveg opened this issue · comments

This code:

def a
  return :foo => "bar"
end

is valid Ruby:

irb(main):001:1* def a
irb(main):002:1*   return :foo => "bar"
irb(main):003:0> end
=> :a
irb(main):004:0> a
=> {:foo=>"bar"}
irb(main):005:0> a.class
=> Hash

Syntax tree formats this code to:

def a
  return foo: "bar"
end

which is not:

irb(main):001:1* def a
irb(main):002:1>   return foo: "bar"
irb(main):003:0> end
/Users/Evan.Goldenberg/.asdf/installs/ruby/3.2.0/lib/ruby/3.2.0/irb/workspace.rb:119:in `eval': (irb):2: syntax error, unexpected ':', expecting `end' or dummy end (SyntaxError)
  return foo: "bar"
            ^

	from /Users/Evan.Goldenberg/.asdf/installs/ruby/3.2.0/lib/ruby/gems/3.2.0/gems/irb-1.6.2/exe/irb:11:in `<top (required)>'
	from /Users/Evan.Goldenberg/.asdf/installs/ruby/3.2.0/bin/irb:25:in `load'
	from /Users/Evan.Goldenberg/.asdf/installs/ruby/3.2.0/bin/irb:25:in `<main>'

Ahh that's annoying. I'll get it fixed, thanks for reporting!