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

Line comment between function an opening brace #5241

Closed
fvictorio opened this issue Oct 10, 2018 · 8 comments · Fixed by #5250
Closed

Line comment between function an opening brace #5241

fvictorio opened this issue Oct 10, 2018 · 8 comments · Fixed by #5250
Labels
area:comments Issues with how Prettier prints comments difficulty:easy Issues that should be easy to fix. Resolve me on the train to work! lang:javascript Issues affecting JS locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. status:has pr Issues with an accompanying pull request. These issues will probably be fixed soon! type:bug Issues identifying ugly output, or a defect in the program

Comments

@fvictorio
Copy link
Contributor

fvictorio commented Oct 10, 2018

If you have the opening brace of a function on its own line, and a line comment after the function signature, the output of prettier is different if you run it once or twice.

Prettier 1.14.3
Playground link

--parser babylon

Input:

function foo() // this is a function
{
  return 42
}

Output:

function foo() { // this is a function
  return 42;
}

Second Output:

function foo() {
  // this is a function
  return 42;
}
@alexander-akait
Copy link
Member

Unstable comment

@alexander-akait alexander-akait added type:bug Issues identifying ugly output, or a defect in the program area:comments Issues with how Prettier prints comments difficulty:easy Issues that should be easy to fix. Resolve me on the train to work! lang:javascript Issues affecting JS labels Oct 10, 2018
@jaideng123
Copy link
Contributor

I can work on this

@jaideng123
Copy link
Contributor

Is the first output the expected behavior?

@alexander-akait
Copy link
Member

@jaideng123 I think second output

@j-f1
Copy link
Member

j-f1 commented Oct 10, 2018

I’d expect the first output to be maintained, but either way works.

@jaideng123
Copy link
Contributor

If I were reading this code it would seem more natural for the comment to be inline (or maybe even above the function declaration?)

@jaideng123
Copy link
Contributor

After digging into this bug a little more I found another layer of instability:

Input:

function foo() 
// this is a function
{
  return 42
}

Output 1:

function foo() // this is a function
{
  return 42
}

Output 2:

function foo() { // this is a function
  return 42
}

Output 3:

function foo() {
  // this is a function
  return 42;
}

@alexander-akait
Copy link
Member

@jaideng123 Just handle 1 and 2 variants

@ikatyang ikatyang added the status:has pr Issues with an accompanying pull request. These issues will probably be fixed soon! label Oct 12, 2018
@lock lock bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label Jan 30, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Jan 30, 2019
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 difficulty:easy Issues that should be easy to fix. Resolve me on the train to work! lang:javascript Issues affecting JS locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. status:has pr Issues with an accompanying pull request. These issues will probably be fixed soon! 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.

5 participants