Skip to content

Consistency in lists/objects #74

Description

@Augustin82

Thanks for your work, I'm VERY interested in something that deals with formatting in my place =)

One thing that struck me upon trying it out tonight, though, was that it does not handle "siblings" consistently. That is, given a list of, say, { id, name } objects; if one of them has a name large enough to reach the line limit, then this object, and this object alone, will be printed over 4 lines, while its siblings will be printed on 1 line. The "exploded" one will have a trailing comma, too, while obviously the one-liners will not.

Original test.js:

const myList = [
  {
    id: 0,
    name: 'Short',
  },
  {
    id: 1,
    name: 'Short Too',
  },
  {
    id: 3,
    name: 'Too Long For Your Line Width',
  },
];

Result ($ prettier --bracket-spacing --trailing-comma --print-width 40 test.js):

const myList = [
  { id: 0, name: "Short" },
  { id: 1, name: "Short Too" },
  {
    id: 3,
    name: "Too Long For Your Line Width",
  },
];

I think that in this case, the original is the better code: it's consistent, easily readable and parsable, at the only cost of taking a lot of vertical space (scrolling is cheap, though).

EDIT: removed JSX example and reworded the issue as per @vramana's comment.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:object literalslocked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.status:needs discussionIssues needing discussion and a decision to be made before action can be taken

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions