ruby-beautify icon indicating copy to clipboard operation
ruby-beautify copied to clipboard

Bad identation when using arrays with embebed objects

Open giovannibenussi opened this issue 9 years ago • 8 comments

When I have this code, it's all ok:

def my_function array = [{ }] end

But, when I change to this: def my_function array = [{ } ] end

That is, put the closing bracket, the end keyword identation fails when I beautify it.

identation_problem

Regards! :-)

giovannibenussi avatar Aug 16 '15 17:08 giovannibenussi

It happens the same when I Have this:

identation_problem_1

identation_problem_2

The plain code is this:

data_daily_aggregated_week = client[:alerts].find().aggregate([{
            "$match": search_options
            }, {
            "$group": {
                "_id": {
                    "hour": {
                        "$dateToString": {
                            format: '%H',
                            date: {
                                "$subtract": ["$pubISODate", 3 * 3600 * 1000] # - 3 Hours
                            }
                        }
                    },
                    "day": {
                        "$dayOfWeek": "$pubISODate"
                    }
                },
                "count": {
                    "$sum": 1,
                }
            },
            }, {
            "$match": {
                "_id.day": {
                    "$in": [1,7]
                }
            }
            }, {
            "$group": {
                "_id": "$_id.hour",
                "count": {
                    "$sum": "$count"
                }
            }
            }, {
            "$project": {
                "hour": "$_id",
                "count": "$count"
            }
        },
        "$sort": {
            "hour": 1
        }])

giovannibenussi avatar Aug 16 '15 17:08 giovannibenussi

Good catch, I'll add it to the list. Hoping to fix all the open bugs by end of month, mid next month.

Gonna take some work as I've got ot od some backend changes.

erniebrodeur avatar Aug 16 '15 18:08 erniebrodeur

Thanks !, I will continue working with my "fix" to it, but it take some time to me to discover that :-P Newbies maybe will appreciate the fix :-)

Good Job!

giovannibenussi avatar Aug 16 '15 19:08 giovannibenussi

@giovannibenussi I'm not really sure what your expected behaviour would be here. I would find

def my_function
(indent)array = [{
(indent)(indent)(indent)code
(indent)}]
end

fairly puzzling.

hzulla avatar Jan 27 '16 13:01 hzulla

@hzulla I use that form when I create an array of hash like this:

image

giovannibenussi avatar Jan 27 '16 18:01 giovannibenussi

@erniebrodeur - I have an idea how to fix this and will try to submit a PR for this next week.

hzulla avatar Jan 27 '16 21:01 hzulla

Sure, if you do put in a PR.

erniebrodeur avatar Jan 27 '16 23:01 erniebrodeur

@erniebrodeur - ok, my idea didn't work out. :-/ So don't expect a PR for this issue.

hzulla avatar Feb 01 '16 16:02 hzulla