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

Comment placement on then/else branches #998

Closed
mitchellwrosen opened this issue Mar 7, 2023 · 1 comment · Fixed by #1092
Closed

Comment placement on then/else branches #998

mitchellwrosen opened this issue Mar 7, 2023 · 1 comment · Fixed by #1092
Labels
comments Issues related to comment placement style Nitpicking and things related to purely visual aspect for formatting.
Milestone

Comments

@mitchellwrosen
Copy link
Contributor

Hi, I'm not sure if the AST would allow us to do this, but it would be great if this formatting of comment placement was preserved by ormolu:

if something
  -- then comment
  then do
    stuff
    stuff
  -- else comment
  else do
    stuff
    stuff

When formatted, this looks like

if something
  then -- then comment
  do
    stuff
    stuff
  else -- else comment
  do
    stuff
    stuff

One workaround is to place comments at the top of each alternative, which is okay, but seems a little less natural.

if something
  then do
    -- then comment
    stuff
    stuff
  else do
    -- else comment
    stuff
    stuff

Thanks!

@mrkkrp mrkkrp added style Nitpicking and things related to purely visual aspect for formatting. comments Issues related to comment placement labels Mar 7, 2023
@brandonchinn178
Copy link
Collaborator

In cases where I actually do want the comment to go after the then/else, the block is de-indented:

Desired:

main =
  if x
    then
      -- asdf
      -- asdf
      case x of
        True -> _
    else
      -- asdf
      -- asdf
      case x of
        True -> _

Actual:

main =
  if x
    then -- asdf
    -- asdf
    case x of
      True -> _
    else -- asdf
    -- asdf
    case x of
      True -> _

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comments Issues related to comment placement 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