Conversation
The custom %% operator (and the built-in F# quotation splice operators %% and %%) can be interpreted by the F# parser as unary prefix operators when they appear at the start of a new line. This caused Fantomas to produce invalid F# code by placing the operator on a new line. The fix adds "%%" to the noBreakInfixOps set, which keeps the operator on the same line as its left-hand-side expression (with the right-hand-side indented below if needed), matching the existing behaviour for %, =, <, >. Fixes #2107 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
28 tasks
…fix-2b39fc63804c7a74
nojaf
approved these changes
Mar 16, 2026
Contributor
|
/repo-assist you did not add a changelog entry here. Please open a new PR for this. |
Contributor
Author
|
Pull request created: #3291
|
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.
🤖 This is an automated PR from Repo Assist.
Closes #2107
Problem
When a
%%infix expression was too long to fit on one line, Fantomas placed the%%operator at the start of the next line:Root Cause
CodePrinter.fsmaintains anoBreakInfixOpsset of operators that must stay on the same line as their LHS (because starting a new line with them changes their parse meaning). The set correctly contained%,=,<,>— but was missing%%. The%%operator therefore fell through to the defaultgenMultilineInfixExprpath, which always puts the operator at the start of the next line.Fix
Add
"%%"tonoBreakInfixOps. When the expression is too long, the%%operator stays at the end of the LHS line and the RHS is indented:This is identical to the existing behaviour for
%,=,<, and>.Test Status
dotnet build src/Fantomas.Core/Fantomas.Core.fsproj)dotnet test src/Fantomas.Core.Tests/)custom double-percent operator stays on same line as lhs when expression is too long, 2107inOperatorTests.fs