awesome-print / awesome_print

Pretty print your Ruby objects with style -- in full color and with proper indentation
http://github.com/michaeldv/awesome_print
MIT License
4.08k stars 454 forks source link

Bad indentation on arrays within object #259

Open xingped opened 8 years ago

xingped commented 8 years ago
screen shot 2016-07-13 at 1 01 37 pm

The object property "films" is an array in this object, but the indentation drops all the way back to the left side of the terminal instead of indenting in place. Not sure if this is intended or cared about, but thought I'd point it out.

waldyr commented 8 years ago

Definitely something wrong. I'm going to investigate it.

waldyr commented 8 years ago

@xingped Could you tell me which version are you using? I could not reproduce it on 1.7.0.

gerrywastaken commented 8 years ago

@waldyr Oh I actually run into this too just recently:

{
    :max_atmosphere_speed => "950",
                   :films => [
        [0] "a",
        [1] "b",
        [2] "c"
    ],
                "created" => "2016"
}

The indent goes back to the start of the longest key (max_atmosphere_speed) in the example above. It happens on master. Maybe we both had .aprc files which were overriding some default?

habermeier commented 8 years ago

Great job on this awesome-print gem. Love it!

Anyhow, not sure this is related, but I'm also getting strange indentation on the following object. Specifically the location object is missing indentation. Interestingly attributes object is not missing indentation.

This is on master branch.

My options are:

AwesomePrint.defaults = {
  ruby19_syntax: true,
  color:  {
    string: :blue
  }
}

The ruby19 syntax doesn't affect this issue (happen either way). And here is the object:

{
    code: 200,
    data: {
        results: [
            [0] {
                              _id: "1008124",
                        has_menus: false,
                     published_at: "2013-08-17T18:22:36",
                  out_of_business: false,
                        has_hours: false,
                         location: {
                            city: "Ketchikon",
                    neighborhood: "",
                    cross_street: "",
                        address1: "344 Frant St",
                        address2: "",
                       longitude: -101.64624,
                      directions: "",
                           state: "JK",
                     postal_code: "90901",
                         country: "IS",
                        latitude: 52.34315
                },
                        sp_photos: true,
                            email: "",
                          website: "",
                          updated: "2013-08-17T18:22:37",
                      description: "",
                            hours: {},
                            phone: "907-200-5555",
                    business_type: "Restiursnt",
                is_owner_verified: true,
                             name: "Swoot Mormoods",
                          created: "2013-08-17T18:22:36",
                      foreign_ids: {},
                        time_zone: "",
                       attributes: {
                             delivery: false,
                              dine_in: false,
                             catering: false,
                         reservations: false,
                             take_out: false,
                           drive_thru: false,
                    wheelchair_access: false
                },
                     is_published: true,
                     location_nid: 1368124,
                      location_id: "sw00t-m00m00ds"
            }
        ],
           next: "http://someting.com/thingies/having_fun/?date=2016-08-17T18:22:37&limit=1&last_record_id=1300124"
    }
}
waldyr commented 8 years ago

I'm going to take another look at it.

waldyr commented 8 years ago

Bug confirmed!

Thanks @habermeier for your example. I'm going to fix it by this weekend so @gerrywastaken can include the fix into the next release 👍

waldyr commented 8 years ago

After investigation I've noticed that next: and results: are both aligned and besides being messy this is the expected behavior of the implemented code.

So @habermeier's example isn't a bug. But @gerrywastaken's definitely is.

habermeier commented 8 years ago

@waldyr I wasn't saying that the bug was around next: and results: It's one level deeper: location: and attributes: They should line up, but do not.

habermeier commented 8 years ago

@waldyr location: entries do not seem to not be indented properly

waldyr commented 8 years ago

Oh...I haven't used your whole example. Sorry.

waldyr commented 8 years ago

@gerrywastaken this is a hard bug. Whenever AP aligns a hash it only aligns its keys and that's why the outdent is wrong. The most problematic thing here is because the alignment is done in the HashFormatter and the array formatting in another formatter (ArrayFormatter) which knows nothing about the width of the alignment.

I'll try again in the upcoming days but I think I will not be able to solve it by the weekend.

gerrywastaken commented 8 years ago

@waldyr I was planning on taking a look myself so cheers for the insight into what is happening. No pressure at all btw, this is open source so anybody is free to fix this and submit a PR.

waldyr commented 8 years ago

I always forgot that haha 👍