Search code examples
angularvisual-studio-codeprettier

VSCode Prettier Keeps separating Condition statements into separate lines


How do I Stop Prettier VSCode Formatter from breaking up equal statements? The following condition statement is broken into two lines, when coding Angular.

if (
   productId ===
   productTest
){

It makes it difficult to read simple code.


Solution

  • Prettier doesn't by default break up equal statements, so either the statement exceeds the maximum print width, or you have another plugin that is somehow interfering.

    You can increase the printwidth by adding a prettier configuration file, e.g. .prettierrc file to the root of your project and setting the printwidth, e.g.

    {
      "printWidth": 100
    }
    

    You can see the full list of configuration file types and options at: https://prettier.io/docs/en/configuration.html
    https://prettier.io/docs/en/options.html