Search code examples
javascripttypescriptformattingprettier

Does Prettier Config Exist for Formatting Switch Statements?


I'm currently using Prettier to format my Typescript code.

This is my problem: if I have some code like this:

switch (someVariable) {
  case "one": return 10;
  case "two": return 20;
  default: return 30;
}

Prettier will format this to:

switch (someVariable) {
  case "one":
    return 10;
  case "two":
    return 20;
  default: 
    return 30;
}

I want to avoid the latter as it adds an additional three lines of code, and makes the entire switch statement less readable and aesthetic.

My question is: is there some prettier config I can include in .prettierrc which will override the formatting of switch statements?


Solution

  • Found a work around: adding a // prettier-ignore comment above a function (or above the switch statement itself) will cause prettier to ignore everything within that function.