Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crash on assginments with do ... end blocks #1198

Closed
pas-f opened this issue Apr 13, 2022 · 5 comments
Closed

crash on assginments with do ... end blocks #1198

pas-f opened this issue Apr 13, 2022 · 5 comments

Comments

@pas-f
Copy link

pas-f commented Apr 13, 2022

Metadata

  • Operating system: WSL2(CentOS)
  • Ruby version: jruby-9.2.19.0
  • Node version: 16.14.2
  • @prettier/plugin-ruby or prettier gem version: latest
  • Options:
    • rubyArrayLiteral - true
    • rubyHashLabel - true
    • rubyModifier - true
    • rubySingleQuote - false
    • rubyToProc - false
    • trailingComma - "none"

Input

Just putting the following line in an empty .rb file and formatting it, crashes the formatter.

b = t.map do |x| x + 10 end

log:

["ERROR" - 9:58:21 AM] Error formatting document.
["ERROR" - 9:58:21 AM] Cannot read properties of undefined (reading 'body')
TypeError: Cannot read properties of undefined (reading 'body')
	at printBlockWithBraces (/project/path/node_modules/@prettier/plugin-ruby/dist/ruby/nodes/blocks.js:40:91)
	at Object.print (/project/path/node_modules/@prettier/plugin-ruby/dist/ruby/printer.js:54:16)
       ...

Yes, the line isn't in line with most style guides. We actually arrive there by first splitting a long assignment over multiple lines, then a second rule replaces {...} with do...end on multi lines blocks. On the next run, we get the crash.

We run prettier and plugin-ruby from a visual studio code server on WSL2/CentOS, I haven't set it up, so I may be missing some details on the configuration and formatting rules.

@kddnewton
Copy link
Member

Hmm, I'm not seeing this error at all on main. Are you sure you're using the latest release?

@kddnewton
Copy link
Member

Oh interesting I see you're using JRuby, let me check that out.

@kddnewton
Copy link
Member

Ah-ha! It's a JRuby bug. Thanks for the report I'll get this fixed.

@kddnewton
Copy link
Member

Ahh... unfortunately this is a known bug with JRuby (jruby/jruby#6642).

kddnewton added a commit that referenced this issue Apr 13, 2022
kddnewton added a commit that referenced this issue Apr 13, 2022
@kddnewton
Copy link
Member

Fixed by #1199

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants