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

Use trailing haddocks for record fields when using leading commas #124

Merged
merged 1 commit into from
Nov 2, 2021

Conversation

georgefst
Copy link
Collaborator

This is inspired by (and lifts the core code from) #98.

Differences:

  • It's rebased on to master.
  • The comments are moved two spaces left. I think this looks better, but I'm happy to hear any dissenting opinions. This is the reason for the removal of the sitcc call in Ormolu.Printer.Meat.Type.
  • There's no separate option. Instead we just follow poCommaStyle, and use trailing haddocks iff it's set to Leading. This removes the "Disallow this in combination with trailing comma style" concern (I'm not sure optparse-applicative provides a nice way to do that). And the old style is so ugly that I really don't see any reason why anyone would prefer it. It's just a relic of adapting Ormolu to leading commas in the simplest way possible.

@expipiplus1
Copy link
Contributor

* The comments are moved two spaces left. I think this looks better, but I'm happy to hear any dissenting opinions. This is the reason for the removal of the `sitcc` call in `Ormolu.Printer.Meat.Type`.

I actually quite prefer to have them indented from the commas, IMO having the commas 'sticking out' like that helps separate the members at glance. When they're lined up with the commas it's kind of one large block; distinguishing dashes from commas is harder than distinguishing space from commas.

I suppose the 'most fourmolu' thing to do would be to make this configurable.

image

@georgefst
Copy link
Collaborator Author

I suppose the 'most fourmolu' thing to do would be to make this configurable.

Ok, sure. Any opinion on naming the flag? I can't think of anything snappier than --indent-trailing-haddocks.

@expipiplus1
Copy link
Contributor

expipiplus1 commented Oct 31, 2021 via email

@georgefst
Copy link
Collaborator Author

georgefst commented Nov 2, 2021

Seems fine to me, it's not as if anyone actually types config options out for a formatter anyway (aside from putting them in their dotfiles once ever).

Good point.

Does make me think that my preference of indenting for records but not for functions is a little inconsistent...

Yeah, it looks pretty weird to me. And doing the analogous thing for functions would require a 3-space indent... But, hey, if you want the option, I'm happy to add it! That's basically our mission statement.

@expipiplus1
Copy link
Contributor

Yeah, it looks pretty weird to me. And doing the analogous thing for functions would require a 3-space indent... But, hey, if you want the option, I'm happy to add it! That's basically our mission statement.

So as to not be difficult, I'll try this out your way, and if it's really as terrible as my knee-jerk reaction, then I'll implement an option for it myself.

@georgefst georgefst merged commit c15784a into master Nov 2, 2021
@georgefst georgefst mentioned this pull request Nov 29, 2021
Comment on lines +5 to +8
{ fooX :: Int
-- ^ X
, fooY :: Int
-- ^ Y
Copy link
Contributor

Choose a reason for hiding this comment

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

Personally, I would imagine it lining up better as

{ fooX :: Int
  -- ^ X
, fooY :: Int
  -- ^ Y

(i.e. same indentation + 2 spaces, regardless of indentation size)

More importantly, if a user did

{ fooX :: Int -- ^ X
, fooY :: Int -- ^ Y

it seems like fourmolu forces these on the next line. I would expect fourmolu to respect the user's newline here (or lack thereof)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

  1. Fair enough, if you and @expipiplus1 both prefer that I'd be happy to support it as an option if someone wants to implement it (once we start clearing the backlog anyway: Merge pull requests #112 (comment)).

  2. That really isn't ideal - I'll look in to it.

Copy link
Collaborator

@brandonchinn178 brandonchinn178 Jan 10, 2022

Choose a reason for hiding this comment

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

  1. Ah I didn't notice it's what @expipiplus1 said. Yeah, no worries, I'm not terribly bothered by it. I'll open a ticket
  2. I'll open a ticket for tracking it

Update: #146 #147

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh this also causes weird behavior when trying to comment sections of record fields:

Original:

data Foo = Foo
  { -- section 1
    a :: Int
  , b :: Int
  , c :: Int
    -- section 2
  , d :: Int
  , e :: Int
  }

fourmolu-0.4.0.0:

data Foo = Foo
  { -- section 1
    a :: Int
  , b :: Int
  , c :: Int
-   -- section 2
- , d :: Int
+ , -- section 2
+   d :: Int
  , e :: Int
  }

fourmolu-0.5.0.0:

data Foo = Foo
  { -- section 1
    a :: Int
  , b :: Int
  , c :: Int
-   -- section 2
- , d :: Int
+ , -- section 2
+ d :: Int
  , e :: Int
  }

Related: #72

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants