ormolu icon indicating copy to clipboard operation
ormolu copied to clipboard

Interesting comment placements in various scenarios

Open LiamGoodacre opened this issue 9 months ago • 1 comments

Describe the bug

Here are a bunch of strange comment placements that I've noticed.

To Reproduce

Positive example

This one looks good

Input, & Output

example =
  [ -- A
    [], -- B
    -- C
    [] -- D
    -- E
  ] -- F

Using QQ in the previous example

Input (& expected output)

example =
  [ -- A
    [u||], -- B
    -- C
    [u||] -- D
    -- E
  ] -- F

Output

example =
  [ -- A
    [u||],
    -- B
    -- C
    [u||]
  ]

-- D
-- E
-- F

Record with comment on each line

Input (& expected output)

example =
  Record
    { -- A
      field = (), -- B
      -- C
      field = (), -- D
      -- E
      .. -- F
    } -- G

Output

example =
  Record
    { -- A
      field = (), -- B
      -- C
      field = (), -- D
      -- E
      ..
    }

-- F
-- G

Records with fewer comments

Notice how -- E here is also moved, which differs from the previous example.

Input (& expected output)

example =
  Record
    { -- A
      field = (),
      -- C
      field = (),
      -- E
      .. -- F
    } -- G

Output

example =
  Record
    { -- A
      field = (),
      -- C
      field = (),
      ..
    }

-- E
-- F
-- G

Environment

  • OS name + version: https://ormolu-live.tweag.io/
  • Version of the code: 0.7.3

LiamGoodacre avatar Nov 09 '23 08:11 LiamGoodacre

Comment in import lists

It looks like ormolu interprets the comment as relating to the import Example3 line.

Input (& expected output)

import Example1
import Example2 ({- comment -})
import Example3

Output

import Example1
import Example2 ()
{- comment -}
import Example3

LiamGoodacre avatar Nov 16 '23 10:11 LiamGoodacre