Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested collection (List, Map) literals are collapsed too aggressively, reducing code readability. #223

Closed
tlarsen4google opened this issue Mar 26, 2015 · 2 comments
Assignees

Comments

@tlarsen4google
Copy link

dartfmt collapsed this:

Foo barBaz() => new Quux({
    'alpha.beta.gamma': [new Zuul({
      'yarrr': Abracadabra.OPEN_SESAME,
    }, {
    'toil': {
      'trouble': {
        'fireBurn': {
            'cauldronBubble': EYE_OF_NEWT,
        }
      }
    }
  })]
});

into the very-compacted:

Foo barBaz() => new Quux({
  'alpha.beta.gamma': [
    new Zuul({'yarrr': Abracadabra.OPEN_SESAME,}, {
      'toil': {'trouble': {'fireBurn': {'cauldronBubble': EYE_OF_NEWT,}}}
    })
  ]
});

The nested structure is much more difficult to discern in the result.

Yes, the original probably does not have style-guide compliant indentation, but indentation correction should not be removing so much visual structure from the code.

@munificent
Copy link
Member

Hmm, I agree the result is hard to read. But I'm not sure what the rule should be here. If a nested collection does all fit on one line, when do you think the formatter should decide to expand it anyway?

@tlarsen4google
Copy link
Author

I personally would advocate for only compressing the single leaf-node collections (that is, collections that do not themselves contain another collection). Nested collections seem to most of the time exist because they represent some sort of structure to the data. Flattening it hides the captured structure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants