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

Adding prettier-ignore comment in JSX doubles the comment #8736

Closed
etr2460 opened this issue Jul 10, 2020 · 1 comment · Fixed by #8742
Closed

Adding prettier-ignore comment in JSX doubles the comment #8736

etr2460 opened this issue Jul 10, 2020 · 1 comment · Fixed by #8742
Labels
area:comments Issues with how Prettier prints comments 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

@etr2460
Copy link

etr2460 commented Jul 10, 2020

Prettier 2.0.5
Playground link

--parser babel

Input:

function HelloWorld() {
  return (
    <div
      {...{} /* 
      // @ts-ignore */ /* prettier-ignore */}
      invalidProp="HelloWorld"
    >
      test
    </div>
  );
}

Output:

function HelloWorld() {
  return (
    <div
      {
        ...{} /* 
      // @ts-ignore */ /* prettier-ignore */ /* 
      // @ts-ignore */ /* prettier-ignore */
      }
      invalidProp="HelloWorld"
    >
      test
    </div>
  );
}

Expected behavior:
I would expect prettier to ignore this ugly block entirely. This is probably a pretty uncommon use case, but I was trying to get a ts-ignore comment to work in JSX by following instructions here (microsoft/TypeScript#27552 (comment)) and ended up in this state where every time I saved the file, prettier auto formatting would double the number of comments I had

@alexander-akait alexander-akait added area:comments Issues with how Prettier prints comments type:bug Issues identifying ugly output, or a defect in the program labels Jul 10, 2020
@thorn0
Copy link
Member

thorn0 commented Jul 10, 2020

While, obviously, this is a bug, wouldn't the following work for your case @etr2460 ?

function HelloWorld() {
  return (
    <div
      // @ts-ignore
      invalidProp="HelloWorld"
    >
      test
    </div>
  );
}

@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 Oct 13, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area:comments Issues with how Prettier prints comments 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.

3 participants