Skip to content

Implement single-deriving-parens#386

Merged
brandonchinn178 merged 3 commits intofourmolu:mainfrom
pbrisbin:pb/single-deriving-parens
Dec 5, 2023
Merged

Implement single-deriving-parens#386
brandonchinn178 merged 3 commits intofourmolu:mainfrom
pbrisbin:pb/single-deriving-parens

Conversation

@pbrisbin
Copy link
Copy Markdown
Contributor

@pbrisbin pbrisbin commented Nov 20, 2023

As discussed in #385.


Make derivedTyClsParensEq more rebust

33c7a8c

The current implementation of this function relies on the fact that we
never output un-parenthesised deriving classes from formatting. This
means the right-hand argument is never a DctSingle. If it ever were,
the function would incorrectly return a Difference no matter what,
even if it were the exact same DctSingle as the left-hand argument.

Since we're about to start making those parenthesis conditional, this
won't work. Instead, we now use considerEqualVia and pattern match on
a comparison of single-to-singleton or singleton-to-single. I find this
a conceptually simpler approach anyway, and is more lenient in the way
we need.

Implement single-deriving-parens

2c8645b

Analogous to single-constraint-parens, this option decides how
deriving clauses should parenthesis single-element lists.

The implementation logic is as follow:

  • If the user typed Show and we are configured for "always", use
    parenthesis. Otherwise ("never" or "auto"), don't.

  • If the user typed (Show) and we are configured for "never", don't
    use parenthesis. Otherwise ("always" or "auto"), do.

Add changelog snippet for single-deriving-parens

2c66260

@github-actions
Copy link
Copy Markdown

👋 @pbrisbin
Thank you for raising your pull request.
Please make sure you have followed our contributing guidelines in DEVELOPER.md. We will review it as soon as possible!

Reviewer: Please verify the following things have been done, if applicable.

  • A file has been added to changelog.d/
  • Docs have been updated in web/site/pages/config/
  • Tests have been added
  • Diff files in compat-tests/ either:
    1. Have NOT been changed, or
    2. Modifies fourmolu.yaml with an appropriate option to keep the same formatting, or
    3. Modifies Haskell files with new formatting (ONLY as a last resort)

@pbrisbin pbrisbin changed the title Pb/single deriving parens Implement single-deriving-parens Nov 20, 2023
@pbrisbin
Copy link
Copy Markdown
Contributor Author

pbrisbin commented Nov 20, 2023

  • A file has been added to changelog.d/
  • Docs have been updated in web/site/pages/config/
  • Tests have been added
  • Diff files in compat-tests/ either:

@pbrisbin
Copy link
Copy Markdown
Contributor Author

I'm a little skeptical of the changelog.d instruction. It seems to contain only the README.md. Am I really the first contributor to contribute something since that's been a required step?

@pbrisbin pbrisbin marked this pull request as ready for review November 20, 2023 18:37
@brandonchinn178
Copy link
Copy Markdown
Collaborator

@pbrisbin if you read the README, it should explain 🙂 Basically, every release, we move everything in changelog.d into CHANGELOG.md. The point of the directory is to avoid merge conflicts when multiple contributors append to the changelog in different PRs

@pbrisbin
Copy link
Copy Markdown
Contributor Author

Thanks, added.

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.

Thanks for putting together such a well-organized PR! I just have a question about why the logic is in Parser and not Printer

Comment thread src/Ormolu/Diff/ParseResult.hs Outdated
Comment thread src/Ormolu/Parser.hs Outdated
@pbrisbin
Copy link
Copy Markdown
Contributor Author

OK, this is ready for another look.

I left the history messy, but can (would prefer to) rebase that before merge, once you let me know the change is good.

I also included some more HLint-related changes that were directly related to what I was touching. I'm happy to leave that out if you prefer.

Comment thread src/Ormolu/Diff/ParseResult.hs Outdated
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.

💯 Much better! Please revert the HLint changes, then feel free to rebase and push

Comment thread src/Ormolu/Diff/ParseResult.hs Outdated
Comment thread .hlint.yaml Outdated
Comment thread src/Ormolu/Printer/Meat/Declaration/Data.hs Outdated
@pbrisbin pbrisbin force-pushed the pb/single-deriving-parens branch from 492e0c7 to 6cc84b6 Compare November 28, 2023 15:05
The current implementation of this function relies on the fact that we
never output un-parenthesised deriving classes from formatting. This
means the right-hand argument is never a `DctSingle`. If it ever were,
the function would incorrectly return a `Difference` no matter what,
even if it were the exact same `DctSingle` as the left-hand argument.

Since we're about to start making those parenthesis conditional, this
won't work. Instead, we now use `considerEqualVia` and pattern match on
a comparison of single-to-singleton or singleton-to-single. I find this
a conceptually simpler approach anyway, and is more lenient in the way
we need.
@pbrisbin pbrisbin force-pushed the pb/single-deriving-parens branch from 6cc84b6 to 2c66260 Compare November 29, 2023 13:37
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.

Looks awesome, thanks! 🚀

@pbrisbin
Copy link
Copy Markdown
Contributor Author

Definitely looks like my fault on the website build failure -- not quite sure what I'm missing.

Comment thread src/Ormolu/Printer/Meat/Declaration/Data.hs Outdated
Comment thread src/Ormolu/Config/Gen.hs
@pbrisbin
Copy link
Copy Markdown
Contributor Author

pbrisbin commented Dec 5, 2023

@brandonchinn178 everything looks green now :)

Would you like me to clean up the history before merge?

@brandonchinn178
Copy link
Copy Markdown
Collaborator

Yes please!

Analogous to `single-constraint-parens`, this option decides how
deriving clauses should parenthesis single-element lists.

The implementation logic is as follow:

- If the user typed `Show` and we are configured for "always", use
  parenthesis. Otherwise ("never" or "auto"), don't.

- If the user typed `(Show)` and we are configured for "never", don't
  use parenthesis. Otherwise ("always" or "auto"), do.
@pbrisbin pbrisbin force-pushed the pb/single-deriving-parens branch from 611f9dc to 68a4dc3 Compare December 5, 2023 16:55
@pbrisbin
Copy link
Copy Markdown
Contributor Author

pbrisbin commented Dec 5, 2023

Done 😄

@brandonchinn178 brandonchinn178 merged commit 5b2755c into fourmolu:main Dec 5, 2023
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.

2 participants