Skip to content

line breaks after assignment instead of between parentheses / around parameters #15208

@fisker

Description

@fisker

Discussed in #15196

Originally posted by macgyver August 1, 2023
Just wondering if anybody can explain the formatting philosophy of converting a line like

  const { section, rubric, authors, tags } = await utils.upsertCommonData(mainData);

into this:

  const { section, rubric, authors, tags } = await utils.upsertCommonData(
    mainData
  );

vs. this:

  const { section, rubric, authors, tags } =
    await utils.upsertCommonData(mainData);

or even

  const { section, rubric, authors, tags }
    = await utils.upsertCommonData(mainData);

(though I recognize that putting operators at the start of a line is controversial)

it seems like keeping the code on two lines vs. three is more parsimonious in terms of vertical space, and groups the concepts better by dividing the code neatly into variable names, and assigned values. Having mainData dangling by itself at the end there just doesn't read that well (to me at least).

What do other folks think? Is there a bigger concept at play here that prevents this from being the behavior? Thanks for your time and insights.

My guess is that Prettier is trying to produce the longest line it can without exceeding the maximum line length, but in cases like this my feeling is that balancing the length of the lines it produces or trying to reduce the total number of lines produced would be a prettier result.

Metadata

Metadata

Assignees

No one assigned

    Labels

    locked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions