Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Line breaks ignored in data type declarations. #947

Closed
jonathanknowles opened this issue Dec 22, 2022 · 1 comment · Fixed by #1096
Closed

Line breaks ignored in data type declarations. #947

jonathanknowles opened this issue Dec 22, 2022 · 1 comment · Fixed by #1096
Labels
style Nitpicking and things related to purely visual aspect for formatting.
Milestone

Comments

@jonathanknowles
Copy link

Describe the bug
Ormolu sometimes eats line breaks within data type declarations.

To Reproduce
Run ormolu on code similar to the following, with a line break before the =:

data SomeReasonablyDescriptiveRecordType someParam1 someParam2 someParam3
 = SomeReasonablyDescriptiveRecordType
   { foo :: someParam1,
     bar :: someParam2,
     baz :: someParam3
   }

or with the line break after the =:

data SomeReasonablyDescriptiveRecordType someParam1 someParam2 someParam3 =
 SomeReasonablyDescriptiveRecordType
   { foo :: someParam1,
     bar :: someParam2,
     baz :: someParam3
   }

Expected behaviour
The line break is preserved, and the data constructor name is indented one level to the right.

Actual behaviour
Ormolu eats the line break, and prints the data constructor name on the same line, resulting in a rather long line:

data SomeReasonablyDescriptiveRecordType someParam1 someParam2 someParam3 = SomeReasonablyDescriptiveRecordType
{ foo :: someParam1,
  bar :: someParam2,
  baz :: someParam3
}

Environment

  • OS name + version: Linux 5.4.0-135-generic #152-Ubuntu SMP Wed Nov 23 20:19:22 UTC 2022 x86_64 GNU/Linux
  • Version of the code: ormolu 0.5.1.0 UNKNOWN UNKNOWN using ghc-lib-parser 9.4.3.20221104

Additional context

  • We have a rather large code base (> 200,000 lines) that's formatted by hand, and we're interested in adopting an auto-formatter.
  • Our team coding standard encourages an 80-column limit.

We realise that ormolu does not provide support for a column limit, but we're wondering if we can get by with manually inserting line breaks where necessary.

Many thanks!
Jonathan

@amesgen
Copy link
Member

amesgen commented Aug 17, 2023

I think respecting line breaks here sounds reasonable, it gets even more annoying with CTYPE pragmas:

data
  {-# CTYPE "header.h" "an-ffi-type-with-along-name"  #-} 
  AnFFITypeWithAlongName = AnFFITypeWithAlongName
  { a :: X,
    b :: Y
  }

is formatted to

data {-# CTYPE "header.h" "an-ffi-type-with-along-name" #-} AnFFITypeWithAlongName = AnFFITypeWithAlongName
  { a :: X,
    b :: Y
  }

without a way to force line breaks without adding bogus comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
style Nitpicking and things related to purely visual aspect for formatting.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants