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

TryCatch block moves the comment an annoying location #13219

Open
adamrybak opened this issue Aug 3, 2022 · 3 comments · May be fixed by #13747
Open

TryCatch block moves the comment an annoying location #13219

adamrybak opened this issue Aug 3, 2022 · 3 comments · May be fixed by #13747

Comments

@adamrybak
Copy link

Prettier 2.7.1
Playground link

Input:

try {
  console.log("try");
} // this is a comment
catch (error) {
  console.error(error);
}

Output:

try {
  console.log("try");
} catch (error) {
  // this is a comment
  console.error(error);
}

Expected behavior:

try {
  console.log("try");
} // this is a comment
catch (error) {
  console.error(error);
}
@dimaMachina
Copy link

I guess it should be

try {
  console.log("try");
} catch (error) { // this is a comment
  console.error(error);
}

@adamrybak
Copy link
Author

I guess it should be

try {
  console.log("try");
} catch (error) { // this is a comment
  console.error(error);
}

No, because the intention is to separate the try catch blocks to make the code more readable and make it more consistent with how if else blocks currently behave.

Example:

if (condition) {
  return "yes";
} // comment
else {
  return "no";
}

@adamrybak
Copy link
Author

Currently the two types of blocks behave differently:

Input:

try {
  console.log("try");
}
//
catch (error) {
  console.log(error);
} 
//
finally {
  console.log("fin");
}

if (condition) {
  return "yes";
}
//
else {
  return "no";
}

Output:

try {
  console.log("try");
} catch (error) {
  //
  console.log(error);
} finally {
  //
  console.log("fin");
}

if (condition) {
  return "yes";
}
//
else {
  return "no";
}

@ortonpaul ortonpaul linked a pull request Oct 28, 2022 that will close this issue
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants