amazing-print / amazing_print

Pretty print your Ruby objects with style -- in full color and with proper indentation
MIT License
783 stars 33 forks source link

Output with ruby19_syntax: true is not copy pastable #90

Closed jakeonrails closed 1 year ago

jakeonrails commented 1 year ago
irb(main):033:0> { one: 1, three: 3, four_hundred: 400}
{
  one         : 1,
  three       : 3,
  four_hundred: 400
}

The spaces between one and the : make this invalid Ruby syntax.

I would expect:

{
  one: 1,
  three: 3,
  four_hundred: 400
}

# or even:
{
  one:          1,
  three:        3,
  four_hundred: 400
}
jakeonrails commented 1 year ago

FYI my defaults:

AmazingPrint.defaults
{
  indent       : -2,
  index        : false,
  multiline    : true,
  ruby19_syntax: true
}
HarlemSquirrel commented 1 year ago

@jakeonrails Sounds like this is only a problem with left-justified keys using indent: -2. Can you confirm this?

jakeonrails commented 1 year ago

Here's the output with various settings:

# Old hash syntax, -2 indent:
AmazingPrint.defaults # =>
{
  :indent        => -2,
  :index         => false,
  :multiline     => true,
  :ruby19_syntax => false
}

# New hash syntax, 2 indent:
AmazingPrint.defaults # =>
{
         indent: 2,
          index: false,
      multiline: true,
  ruby19_syntax: true
}

So yes I think it's only an issue with left/-2. The spacing is not great on the old hash syntax, but at least you can still copy/paste that and execute as valid ruby code. So it's really a combo of new hash + -indent.