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

Long lines of code need to be formatted twice #12413

Closed
zsakowitz opened this issue Mar 7, 2022 · 1 comment · Fixed by #12508
Closed

Long lines of code need to be formatted twice #12413

zsakowitz opened this issue Mar 7, 2022 · 1 comment · Fixed by #12508
Labels
area:idempotency Issues with re-printing Prettier’s output lang:typescript Issues affecting TypeScript-specific constructs (not general JS issues) locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. type:bug Issues identifying ugly output, or a defect in the program

Comments

@zsakowitz
Copy link

Prettier 2.5.1
Playground link, second playground link

--parser typescript

Input:

let emit =
    defineEmits<{ (event: "ready", canvas: HTMLCanvasElement): void; (event:"resize",canvas:HTMLCanvasElement):void; }>();

Output:

let emit =
  defineEmits<{
    (event: "ready", canvas: HTMLCanvasElement): void;
    (event: "resize", canvas: HTMLCanvasElement): void;
  }>();

Output upon reformatting:

let emit = defineEmits<{
  (event: "ready", canvas: HTMLCanvasElement): void;
  (event: "resize", canvas: HTMLCanvasElement): void;
}>();

Issue:
Upon reformatting the code, Prettier gives a different response than the original.

Expected behavior:
Prettier should only require a single formatting to correctly format the code.

@kachkaev kachkaev added area:idempotency Issues with re-printing Prettier’s output lang:typescript Issues affecting TypeScript-specific constructs (not general JS issues) type:bug Issues identifying ugly output, or a defect in the program labels Mar 8, 2022
@zsakowitz
Copy link
Author

I've noticed this is often an issue when combining TypeScript generics with object literals. Here's a second example for reference:

Prettier 2.5.1
Playground link, Second playground link

--parser typescript

Input:

function func<T>() {}

let abc=
     func<{a:2,b:3,d:78,e:9,f:8,g:7,h:6,i:5,j:4,k:3,l:2,m:1,n:0,o:9,p:8,q:7,r:6,s:5,t:4,u:3,v:2,w:1,x:0,y:9,z:8}>();

Output:

function func<T>() {}

let abc =
  func<{
    a: 2;
    b: 3;
    d: 78;
    e: 9;
    f: 8;
    g: 7;
    h: 6;
    i: 5;
    j: 4;
    k: 3;
    l: 2;
    m: 1;
    n: 0;
    o: 9;
    p: 8;
    q: 7;
    r: 6;
    s: 5;
    t: 4;
    u: 3;
    v: 2;
    w: 1;
    x: 0;
    y: 9;
    z: 8;
  }>();

Output upon reformatting:

function func<T>() {}

let abc = func<{
  a: 2;
  b: 3;
  d: 78;
  e: 9;
  f: 8;
  g: 7;
  h: 6;
  i: 5;
  j: 4;
  k: 3;
  l: 2;
  m: 1;
  n: 0;
  o: 9;
  p: 8;
  q: 7;
  r: 6;
  s: 5;
  t: 4;
  u: 3;
  v: 2;
  w: 1;
  x: 0;
  y: 9;
  z: 8;
}>();

Expected behavior:
This is another example where Prettier requires two passes to format the code correctly.

@github-actions github-actions bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label Jun 22, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area:idempotency Issues with re-printing Prettier’s output lang:typescript Issues affecting TypeScript-specific constructs (not general JS issues) locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. type:bug Issues identifying ugly output, or a defect in the program
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants