tweag / ormolu

A formatter for Haskell source code
https://ormolu-live.tweag.io
Other
958 stars 83 forks source link

Adding ORMOLU_DISABLE moves block #693

Closed brandon-leapyear closed 3 years ago

brandon-leapyear commented 3 years ago

Describe the bug Adding a ORMOLU_DISABLE/ORMOLU_ENABLE block before a where clause cause ormolu to move the block into the where clause

To Reproduce

asdf :: IO ()
asdf = do
  x <- foo
  {- ORMOLU_DISABLE -}
  return (x,x)
  {- ORMOLU_ENABLE -}
  where
    foo = pure 1

Running ormolu on this gives

asdf :: IO ()
asdf = do
  x <- foo
  where
    {- ORMOLU_DISABLE -}
    return (x,x)
    {- ORMOLU_ENABLE -}

    foo = pure 1

Same thing happens if the ORMOLU comments are not indented

Expected behavior Code should stay the same

Environment

Additional context Add any other context about the problem here.

mrkkrp commented 3 years ago

ORMOLU_DISABLE is only meant to be used around top-level forms, not selectively around expressions like this. I do not consider this a bug, a feature request perhaps.

mrkkrp commented 3 years ago

The readme says:

Because of that the magic comments cannot be placed arbitrarily, but rather must enclose independent top-level definitions.

brandon-leapyear commented 3 years ago

:sparkles: This is an old work account. Please reference @brandonchinn178 for all future communication :sparkles:


Interesting... I was able to work around this with

asdf :: IO ()
asdf = go
  where
    {- ORMOLU_DISABLE -}
    go = do
      x <- foo
      return (x,x)
    {- ORMOLU_ENABLE -}

    foo = pure 1

which works, so perhaps an undocumented feature? But yes, then this issue is a feature request

mrkkrp commented 3 years ago

The feature is a bit of a hack. Surely, it'll accidentally work is some cases, but this usage is not something we officially support.