prettier / prettier-vscode

Visual Studio Code extension for Prettier
https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode
MIT License
5.04k stars 446 forks source link

Try to keep arrow function parameters and bodies on the same line #3292

Closed justingrant closed 3 months ago

justingrant commented 3 months ago

Is your feature request related to a problem? Please describe.

Prettier splits arrow functions across lines, like this:

export const materialName = (mat: Material) =>
  `${mat.manufacturer.name} ${mat.name} ${mat.color}`;

I found this surprising because parameters and body of a function are very closely related so it'd be nice to keep them on the same line if possible.

Describe the solution you'd like

export const materialName = 
  (mat: Material) => `${mat.manufacturer.name} ${mat.name} ${mat.color}`;

Describe alternatives you've considered

My colleague in a code review asked me to convert this arrow function to use curly braces to avoid the split, like this:

function materialName(mat: Material) {
  return `${mat.manufacturer.name} ${mat.name} ${mat.color}`;
}

This is a pretty big refactor! I'd like to avoid these in the future.

This matches our style for if and else statements where we always put curly braces around muilti-line conditionals like this:


// OK
if (foo) return true; // OK
if (foo) {
  return true;
}

// Not OK with our team's code style; too easy to lose the `if` and end up with a dangling `return`;
if (foo)
  return true; 

Additional context Add any other context or screenshots about the feature request here.

justingrant commented 3 months ago

Whoops, sorry I posted this into pretter-vscode instead of the main prettier repo. Sorry for the noise. Closing.

Real issue is here: https://github.com/prettier/prettier/issues/16006

github-actions[bot] commented 2 weeks ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.