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.

deeply nested object literals

See original GitHub issue

Currently deeply nested object literals will be formatted in a collapsed form.

This behavior is nice for simple object literals, but for deeply nested ones it would be nice to have the nested properties indented. Maybe a complexity level (like for Arrow expressions) would be nice here.

source

var simple = {
name:'a'
}

var deeplyNested = {
    name:'f',
    nested: {
    	nested: {
    		nested: {
    			nested: {
    				nested: {
    					nested: {
    						nested: {
    							name: 'a'
    						}
    					}
    				}
    			}
    		}
    	}
    }
};

formatted

var simple = {name: 'a'};

var test = {
  name: 'f',
  nested: {
    nested: {nested: {nested: {nested: {nested: {nested: {name: 'a'}}}}}}
  }
};

https://vjeux.github.io/prettier-browser/#{“content”%3A"\nvar simple %3D {\nname%3A’a’\n}\n\nvar test %3D {\n name%3A’f’%2C\n nested%3A {\n \tnested%3A {\n \t\tnested%3A {\n \t\t\tnested%3A {\n \t\t\t\tnested%3A {\n \t\t\t\t\tnested%3A {\n \t\t\t\t\t\tnested%3A {\n \t\t\t\t\t\t\tname%3A ‘a’\n \t\t\t\t\t\t}\n \t\t\t\t\t}\n \t\t\t\t}\n \t\t\t}\n \t\t}\n \t}\n }\n}%3B"%2C"options"%3A{“printWidth”%3A80%2C"tabWidth"%3A2%2C"useFlowParser"%3Afalse%2C"singleQuote"%3Atrue%2C"trailingComma"%3Afalse%2C"bracketSpacing"%3Afalse}}

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:4
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
lydellcommented, Jan 26, 2017

As another real-world example, here’s an excerpt from a brunch-config.js (for brunch) file in one of my projects after running prettier on it:

    uglify: { compress: { drop_console: true, global_defs: { DEBUG: false } } },
    autoReload: { enabled: false }
  },
  overrides: { autoreload: { plugins: { autoReload: { enabled: true } } } }
0reactions
vjeuxcommented, Jan 27, 2017

https://github.com/jlongster/prettier/issues/74 is also talking about the same issue, let’s condensate them into one. Closing this one.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Flattening a deeply nested array of literals in JavaScript
The function should construct a new array that contains all the literal elements present in the input array but without nesting.
Read more >
How to explore a deeply nested object structure more easily?
Object Literal and spread operator makes creating deeply nested object very easy. But from time to time I have to read the code...
Read more >
How to safely work with nested objects in JavaScript
Safely setting values for deeply nested objects. Using Lodash. We can use Lodash's set function. Below is the syntax set(object, path, value).
Read more >
Using ES6 To Destructure Deeply Nested Objects in ... - ITNEXT
Today, I will show you how to use ES6 to destructure nested objects, my friends, AND what's more, prevent the dreaded undefined error...
Read more >
How to Merge Deeply Nested Objects in JavaScript
There are many scenarios where we need to merge two objects that may be deeply nested. In this article, we will see how...
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