Add leading commas option for module import-export lists#108
Add leading commas option for module import-export lists#108brandonchinn178 merged 18 commits intofourmolu:masterfrom 3kyro:master
Conversation
|
Formatting when comma style is set to leading: >>>>>>>>>>>>>>>>>>>>>> trailing:
module Foo
( foo,
bar,
baz,
)
where
>>>>>>>>>>>>>>>>>>>>>> leading:
module Foo
( foo
, bar
, baz
)
where >>>>>>>>>>>>>>>>>>>>>> trailing:
import qualified MegaModule as M
( Either,
Maybe (Just, Nothing),
MaybeT (..),
Monad (return, (>>), (>>=)),
MonadBaseControl,
join,
liftIO,
void,
(<<<),
(>>>),
)
>>>>>>>>>>>>>>>>>>>>>> leading:
import qualified MegaModule as M
( Either
, Maybe (Just, Nothing)
, MaybeT (..)
, Monad (return, (>>), (>>=))
, MonadBaseControl
, join
, liftIO
, void
, (<<<)
, (>>>)
)>>>>>>>>>>>>>>>>>>>>>> trailing:
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TypeFamilies #-}
-- | Header.
module My.Module
( -- * Something
foo,
bar,
-- | A multiline
-- comment here
bar2,
-- * Another thing
(<?>),
{- some other thing -} foo2, -- yet another
foo3, -- third one
baz,
bar2, -- a multiline comment
-- the second line
bar3,
module Foo.Bar.Baz,
)
where
-- Wow
>>>>>>>>>>>>>>>>>>>>>> leading:
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TypeFamilies #-}
-- | Header.
module My.Module
( -- * Something
foo
, bar
-- | A multiline
-- comment here
, bar2
-- * Another thing
, (<?>)
{- some other thing -} , foo2 -- yet another
, foo3 -- third one
, baz
, bar2 -- a multiline comment
-- the second line
, bar3
, module Foo.Bar.Baz
)
where
-- Wow |
Changed `import-export-comma-style` to the correct `ie-comma-style`.
|
I fumbled a bit with the configuration options, but should be good now. 😄 |
Before:
module My.Module
( -- * Something
foo
, bar
After:
module My.Module
( -- * Something
foo
, bar
|
Hi, what forbids this PR from getting merged? I'm glad to help. |
It kind of got stuck waiting for #49 . We are actually considering whether to use fourmolu at work, and having this option is important. @georgefst Is there something else that would forbid this to get reviewed and merged? |
brandonchinn178
left a comment
There was a problem hiding this comment.
Reference for the comments about conflicting with upstream: https://github.com/fourmolu/fourmolu/blob/master/DEVELOPER.md#contributing
Renaming the config option is my biggest concern otherwise. I'll leave the new tests (and decision on whether to block on #49) to @georgefst
data/examples/module-header/multiline-with-comments-four-ie-out.hs
Outdated
Show resolved
Hide resolved
Regarding testing, this PR adds new test files where necessary that test output only with the new option enabled. Regarding #49 I kind of feel that a leading commas option import export lists is more of a continuation of the way fourmolu fundamentally differs from ormolu regarding lists rather than a specific one way option. That being said, I'm happy to conform to a specific test format when one is decided. @georgefst I would really appreciate your input. |
|
@brandonchinn178 Anything I could do to help this PR getting merged? :) I'm also oscillating towards Fourmolou thanks to this PR. |
|
All of my comments have been addressed. It's up to @georgefst on what to do about testing |
|
Thank you very much. :) |
parsonsmatt
left a comment
There was a problem hiding this comment.
I’m in favor and would love to have this feature in.
I’m sympathetic to the testing argument. Obviously testing the combinatorics possibilities of all configuration options isn’t tenable. But I think it should be possible to trim that state space considerably
|
Ping. Could this be merged? |
|
@georgefst Would you be ok merging this now? Also, can you email me so we can briefly chat about how to coordinate changes to fourmolu? (my emails in my GitHub profile) cc @parsonsmatt if you want to be included in that conversation as well, email me and I'll keep you in the loop |
Sure. I'm willing to make an exception in this case, due to the PR containing its own tests, and the sheer level of demand as evidenced by comments and reactions. Besides, code changes (other than tests) are fairly small and @brandonchinn178 appears to have reviewed thoroughly.
Done. |
There is an important difference here between import/export lists, and list literals. Which is that the former allows extra commas, which means we can make the trailing style more uniform. In fact, I'd argue that they're two quite separate concepts that just happen to have similar syntax, and thus there isn't any great argument against using trailing commas for one and leading commas for the other. So I feel quite strongly that the two options should be separate, and that we should maintain the current default behaviour (which, of course, is what this PR now does). (I've made this point somewhere before in a related conversation, but I can't find it right now) |
|
@georgefst Thank you for this important precision, this is indeed something that I wasn't quite aware of. :) |
|
I'm very happy this feature is now available. |
|
I'm planning on doing a release in a couple weeks, is that ok? |
|
Sure, no pressure. Just wanted to get a sense of what to expect. Thanks for working on this 😃 |
|
FYI module Foo (
foo
, bar
, baz
) where
import qualified MegaModule as M (
Either
, Maybe (Just, Nothing)
, MaybeT (..)
, Monad (return, (>>), (>>=))
, MonadBaseControl
, join
, liftIO
, void
, (<<<)
, (>>>)
)Not sure how this option should behave in this case Ref: 886855c |
|
This seems appropriate: module Foo (
foo
, bar
, baz
) where |
That is probably the best we can do, which neatly indicates that the "diff-friendly"-ness of the latter goes out the window with leading commas. So using both together seems undesirable. Hmm. Ideally these would be combined in to a single ternary option, but maybe it's not worth the breakage. Otherwise we can just mention in the option docs (which I think are being worked on in #169) that they interact weirdly. |
|
@georgefst Yes, I think being truthful about the interactions might be the best way to continue. :) |
|
Something like |
The implementation passes all tests when import-export comma style is set to trailing, and only fails expected formatting tests when set to leading.
Probably needs to wait #106 to be merged first.
Fixes #61