question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Formatting an array of objects not working as expected

See original GitHub issue

Description

I submitted this question on SO, but I have a feeling it’s an issue with the parser itself.

I want to both preserve my newlines and have my braces be on the same line as a bracket or other brace.

If I turn preserve_newlines off, then the formatting works except that my newlines are no longer there. How do I set up my config file to get the desired output?

Input

The code looked like this before beautification:

{
  someFunction: function() {

  },

  arr: [{
    thing: 1
  }, {
    one: 2
  }],
  arr2: [{
        thing: 1
    },
     {
        one: 2
    }]
}

Desired Output

The code should have looked like this after beautification:

{
    someFunction: function() {

    },

    arr: [{
        thing: 1
    }, {
        one: 2
    }],
    arr2: [{
        thing: 1
    }, {
        one: 2
    }]
}

Actual Output

The code actually looked like this after beautification:

{
    someFunction: function() {

    },

    arr: [{
        thing: 1
    }, {
        one: 2
    }],
    arr2: [{
            thing: 1
        },
        {
            one: 2
        }
    ]
}

Steps to Reproduce

Environment

OS:

Settings

Example:

{
    "indent_size": 4,
    "indent_char": " ",
    "indent_with_tabs": false,
    "eol": "\\n",
    "end_with_newline": true,
    "indent_level": 0,
    "preserve_newlines": true,
    "max_preserve_newlines": 10,
    "space_in_paren": false,
    "space_in_empty_paren": false,
    "jslint_happy": false,
    "space_after_anon_function": false,
    "brace_style": "end-expand",
    "unindent_chained_methods": false,
    "break_chained_methods": false,
    "keep_array_indentation": false,
    "unescape_strings": false,
    "wrap_line_length": 0,
    "e4x": false,
    "comma_first": false,
    "operator_position": "before-newline"
}

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
HanabishiReccacommented, Apr 29, 2019

@bitwiseman, maybe. I like the idea to separate brace_style for code and array_style for arrays/objects. Mostly because of JSON formatting.

1reaction
HanabishiReccacommented, Apr 28, 2019

Also when brace_style: "collapse" we have

Input

[
    {
        param: value,
    },
    {
        param: value,
    }
]

Desired (unchanged)

Actual

[{
        param: value,
    },
    {
        param: value,
    }
]

I really suffer beacuse of it )

Read more comments on GitHub >

github_iconTop Results From Across the Web

Formatting the Array of objects [duplicate] - Stack Overflow
How do I convert array of Objects into one Object in JavaScript? ... That data structure is what you want to get, not...
Read more >
Trailing commas - JavaScript - MDN Web Docs
JavaScript allows trailing commas wherever a comma-separated list of values is accepted and more values may be expected after the last item.
Read more >
Everything you wanted to know about arrays - PowerShell
Adding items to an array is one of its biggest limitations, but there are a few other collections that we can turn to...
Read more >
Arrays | Elasticsearch Guide [8.5] | Elastic
Arrays of objects do not work as you would expect: you cannot query each object independently of the other objects in the array....
Read more >
Semi-structured Data Types - Snowflake Documentation
Snowflake can convert data from JSON, Avro, ORC, or Parquet format to an internal hierarchy of ARRAY, OBJECT, and VARIANT data and store...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found