Fix idempotency issue with comment after type decl without equals, 3145#3163
Merged
dawedawe merged 5 commits intofsprojects:mainfrom May 20, 2025
Merged
Fix idempotency issue with comment after type decl without equals, 3145#3163dawedawe merged 5 commits intofsprojects:mainfrom
dawedawe merged 5 commits intofsprojects:mainfrom
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR fixes an idempotency issue where a type declaration without an = but with a trailing comment would always emit an extra newline.
- Introduces a new formatter function that omits the newline in this specific case
- Updates
genTypeDefnto pick newline vs. no-newline behavior based on presence ofEqualsToken - Adds a targeted test and updates the changelog entry
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Fantomas.Core/Context.fsi | Added signature for sepSpaceOrIndentIfExpressionExceedsPageWidth |
| src/Fantomas.Core/Context.fs | Implemented new separator and wired it into expression logic |
| src/Fantomas.Core/CodePrinter.fs | Updated genTypeDefn to select between the two separator functions |
| src/Fantomas.Core.Tests/TypeDeclarationTests.fs | Added test for type decl without = and trailing comment |
| CHANGELOG.md | Documented the fix under Fixed |
Comments suppressed due to low confidence (2)
src/Fantomas.Core.Tests/TypeDeclarationTests.fs:3686
- Add a complementary test for a type alias with an
=and trailing comment to ensure the original newline logic (sepSpaceOrIndentAndNlnIfExpressionExceedsPageWidth) remains correct.
let ``type without body but with comment produces superfluous newline, 3145`` () =
src/Fantomas.Core/Context.fs:751
- [nitpick] Consider renaming this function to something like
sepSpaceOrIndentWithoutNlnIfExpressionExceedsPageWidthto more clearly indicate that it omits the newline behavior.
let sepSpaceOrIndentIfExpressionExceedsPageWidth expr (ctx: Context) =
nojaf
reviewed
May 19, 2025
…an equals" This reverts commit d558322.
…geWidth conditional in else branch via optSingle
Contributor
|
@dawedawe do we want to release a 7.0.2? |
Member
Author
I'll look into one or two more fixes in the next couple of days. Let's release after that. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3145
It's actually about type decls without an equals but a comment after.
See here
Ideally we could detect that in
expressionExceedsPageWidth(or even below that) as theinfo.ConfirmedMultilineis the root cause, but I don't see a good way to pass that down there.