Home > Blockchain >  How to change Haskell code formatting rules in VS Code
How to change Haskell code formatting rules in VS Code

Time:10-08

I'm using VS Code with the Haskell extension v2.2.1 and the Haskell Syntax Highlighting extension v3.6.0.

When I write:

data Name = Name
  { first :: String
  , last :: String }

And I invoke formats election on it I end up with

data Name = Name
  { first :: String,
    last :: String
  }

How can I change this behaviour, so that it keeps the first way of formatting (with leading commas)?

CodePudding user response:

The default formatter for the Haskell extension is ormolu which always uses trailing commas.

In the VSCode settings for the Haskell extension you can choose a different formatter. For example fourmolu which is a fork of ormolu with more configuration options. It has a setting for the comma style:

comma-style | leading, trailing | Where to place commas in lists, tuples, etc.

  • Related