Skip to content

Add leading commas option for module import-export lists#108

Merged
brandonchinn178 merged 18 commits intofourmolu:masterfrom
3kyro:master
Mar 21, 2022
Merged

Add leading commas option for module import-export lists#108
brandonchinn178 merged 18 commits intofourmolu:masterfrom
3kyro:master

Conversation

@3kyro
Copy link
Copy Markdown
Contributor

@3kyro 3kyro commented Aug 24, 2021

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

@3kyro
Copy link
Copy Markdown
Contributor Author

3kyro commented Aug 24, 2021

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

@3kyro 3kyro changed the title Add leading commas for module import-export lists Add leading commas option for module import-export lists Aug 24, 2021
@3kyro 3kyro marked this pull request as draft August 24, 2021 15:36
3kyro added 3 commits August 24, 2021 17:39
Changed `import-export-comma-style` to the correct `ie-comma-style`.
@3kyro
Copy link
Copy Markdown
Contributor Author

3kyro commented Aug 24, 2021

I fumbled a bit with the configuration options, but should be good now. 😄

@3kyro 3kyro marked this pull request as ready for review August 24, 2021 16:47
wldhx added a commit to wldhx/fourmolu that referenced this pull request Sep 9, 2021
@pepeiborra pepeiborra mentioned this pull request Sep 22, 2021
wldhx added a commit to wldhx/fourmolu that referenced this pull request Sep 30, 2021
Before:
    module My.Module
    ( -- * Something
      foo
      , bar

After:
    module My.Module
     ( -- * Something
       foo
     , bar
@georgefst georgefst mentioned this pull request Oct 30, 2021
@novadev94
Copy link
Copy Markdown

Hi, what forbids this PR from getting merged? I'm glad to help.

@3kyro
Copy link
Copy Markdown
Contributor Author

3kyro commented Jan 20, 2022

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?

Copy link
Copy Markdown
Collaborator

@brandonchinn178 brandonchinn178 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@brandonchinn178 brandonchinn178 added the new config option Adds or would add new configuration option label Jan 24, 2022
@3kyro
Copy link
Copy Markdown
Contributor Author

3kyro commented Feb 5, 2022

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

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.

@3kyro 3kyro requested a review from brandonchinn178 February 5, 2022 20:27
@tchoutri
Copy link
Copy Markdown

tchoutri commented Mar 6, 2022

@brandonchinn178 Anything I could do to help this PR getting merged? :) I'm also oscillating towards Fourmolou thanks to this PR.

@brandonchinn178
Copy link
Copy Markdown
Collaborator

All of my comments have been addressed. It's up to @georgefst on what to do about testing

@tchoutri
Copy link
Copy Markdown

tchoutri commented Mar 6, 2022

Thank you very much. :)

Copy link
Copy Markdown
Collaborator

@parsonsmatt parsonsmatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@arybczak
Copy link
Copy Markdown

Ping. Could this be merged?

@brandonchinn178
Copy link
Copy Markdown
Collaborator

@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

@georgefst
Copy link
Copy Markdown
Collaborator

@georgefst Would you be ok merging this now?

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.

Also, can you email me so we can briefly chat about how to coordinate changes to fourmolu?

Done.

@brandonchinn178 brandonchinn178 merged commit 0eb1681 into fourmolu:master Mar 21, 2022
@georgefst
Copy link
Copy Markdown
Collaborator

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

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)

@tchoutri
Copy link
Copy Markdown

@georgefst Thank you for this important precision, this is indeed something that I wasn't quite aware of. :)

@jhrcek
Copy link
Copy Markdown
Contributor

jhrcek commented Mar 25, 2022

I'm very happy this feature is now available.
Are there any plans to release new version of fourmolu with this feature?

@brandonchinn178
Copy link
Copy Markdown
Collaborator

I'm planning on doing a release in a couple weeks, is that ok?

@jhrcek
Copy link
Copy Markdown
Contributor

jhrcek commented Mar 25, 2022

Sure, no pressure. Just wanted to get a sense of what to expect. Thanks for working on this 😃

@brandonchinn178
Copy link
Copy Markdown
Collaborator

brandonchinn178 commented Apr 17, 2022

FYI import-export-comma-style=Leading looks a bit weird with diff-friendly-import-export=True:

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

@tchoutri
Copy link
Copy Markdown

This seems appropriate:

module Foo (
      foo
    , bar
    , baz
) where

@georgefst
Copy link
Copy Markdown
Collaborator

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.

@tchoutri
Copy link
Copy Markdown

@georgefst Yes, I think being truthful about the interactions might be the best way to continue. :)

@brandonchinn178
Copy link
Copy Markdown
Collaborator

Something like import-export-style: diff-friendly, leading, trailing would be nice. I'll keep it in mind if we ever add more options to this area

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new config option Adds or would add new configuration option

Projects

None yet

Development

Successfully merging this pull request may close these issues.

comma-style: leading doesn't apply to import and export lists

8 participants