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.

Awkward formatting of elisions in array assignment patterns

See original GitHub issue

Prettier 1.19.1 Playground link

--parser babel

Input:

switch (LTocurrenceCount) {
        case 1: 
          itemToAddToFinalResult = item;
          break;
        case 2: {
          const [, secondDuplicateIdx] = mappingWithPossibleDoubledInputs
            .map((item1, idx1) => (item1.labelText === labelText ? idx1 : undefined))
            .filter(Boolean);
          if (idx === secondDuplicateIdx) {
            itemToAddToFinalResult = give_special_treatment(item);
          } else itemToAddToFinalResult = item;
          break;
        }
        default:
          console.error("more than 2 occurences!");
      }

Output:

switch (LTocurrenceCount) {
  case 1:
    itemToAddToFinalResult = item;
    break;
  case 2: {
    const [
      ,
      secondDuplicateIdx
    ] = mappingWithPossibleDoubledInputs
      .map((item1, idx1) => (item1.labelText === labelText ? idx1 : undefined))
      .filter(Boolean);
    if (idx === secondDuplicateIdx) {
      itemToAddToFinalResult = give_special_treatment(item);
    } else itemToAddToFinalResult = item;
    break;
  }
  default:
    console.error("more than 2 occurences!");
}

Expected behavior: I would expect the const [, secondDuplicateIdx] part not to break into muplitple lines.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
fiskercommented, Feb 8, 2020

Array with holes

Prettier 1.19.1 Playground link

--parser babel

Input:

const arrayWithManyHoles = [
  first, , , , , , , , , , , , , , , , , , , , , , , , ,
  last
]

Output:

const arrayWithManyHoles = [
  first,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  last
];

Expected:

Maybe keep holes after the first one, like input.

1reaction
thorn0commented, Dec 5, 2019

@brodybits Please add Expected because to me it’s not clear what’s wrong with the current output.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Odd splitting when destructuring · Issue #3227 · prettier/prettier ...
Awkward formatting of elisions in array assignment patterns #7089. Open. @thorn0 thorn0 added the area:destructuring label on May 6, 2020.
Read more >
The OCaml system release 4.06 - The Caml language
This manual documents the release 4.06 of the OCaml system. It is organized as follows. • Part I, “An introduction to OCaml”, ...
Read more >
CoffeeScript
CoffeeScript is a little language that compiles into JavaScript. Underneath that awkward Java-esque patina, JavaScript has always had a gorgeous heart.
Read more >
typescript-cheatsheet - GitHub Pages
const hobbies: string[] = ['Programming', 'Cooking'];. If no types are declared, TypeScript will automatically assign a type depending on the types of the...
Read more >
ECMA-262 Edition 5.1 - ECMAScript Language Specification
15.4.1 The Array Constructor Called as a Function; 15.4.2 The Array ... array manipulation functions, support for the JSON object encoding format, ...
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