prettier
prettier copied to clipboard
TryCatch block moves the comment an annoying location
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);
}
I guess it should be
try {
console.log("try");
} catch (error) { // this is a comment
console.error(error);
}
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";
}
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";
}