-
Notifications
You must be signed in to change notification settings - Fork 6k
Specify that rules for explicit generic type arguments also apply to function application #26256
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
Conversation
ping @dsyme for review |
@nojaf what do you think? I see the inconsistency but type applications are perhaps a bit different |
I don't want to start a big discussion, just wondering, how is it different? With the current behavior of Fantomas, you still get potentially significant code chunks (as in the demo) moved off to the right and potentially breaking your code on rename (due to offsets changing). This is in violation of the "avoid name sensitive alignments" clause which is already part of the guide. |
For example, with Fantomas' current behavior, if you rename This PR is basically just to make it absolutely clear; I don't see it as a prerequisite for the Fantomas change due to the aforementioned reasons (breakage on rename + avoid name-sensitive alignments should be sufficient reasons). |
I see, yes, that's a good argument from principle. I've not often done multi-line generic argument instantiations so my intuitions aren't so good here. The only different I thought of is that the But what's the actual rule? Is it that a multi-line anon record type should always start Json.serialize<
{| child:
{| displayName: string
longLongLongLongLongKind: string |}
newParent:
{| id: string
longLongLongLongDisplayName: string |}
requiresApproval: bool |}> etc.? That's needed to make it robust to renaming? It's not really about generic instantiations is it? This would apply to any multi-line anon record type formatting? |
I don't get it. Sure, the code breaks due to offsets coming from the anonymous record. But the proposed change in this PR is still sound from a principle standpoint, as argued. The formatting guidelines can of course introduce something about anonymous records specifically, but that is not itself relevant to this PR. The code breakage occur only because of the way Fantomas formats the generic parameters, which I guess it would do whether or not there is an anonymous record there. |
@cmeeren I think your suggestion is fine, I just want to discuss with @nojaf what the actual rule is. The rules immediately preceeding your addition are describing what to do with
Your example is
and saying it should be
That's ok - it's just that AFAICS it doesn't really following from the other rules described, and we should consider all the cases where this arises and check we are doing things consistently. |
I see. I'll let you two hash this out. 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good, thank you. We'll when you make the suggested changes.
Hi friends, hey @dsyme - are you good with this, or should it be changed? |
Co-authored-by: David Pine <[email protected]>
My concerns here weren't really fully resolved, but the change is still basically ok |
Hello, I have missed all of this I'm afraid. As for SomeDatabase.CreateCommand<"
select name
from things
where id = :id
" > The position of Fantomas currently does not have anything in place for doing something different when the type is multiline. On a side note, I'm also wondering about putting the closing Json.serialize<
{| child: {| displayName: string; kind: string |}
newParent: {| id: string; displayName: string |}
requiresApproval: bool |}
> The same for anonymous type definitions, nothing really is in place. |
It makes sense that the same rules should apply to explicit generic parameters in function application, too.
Currently Fantomas formats this in a way that breaks the "avoid name-sensitive alignment" clause:
Here is a better formatting that is consistent with the rules for function/member/type definitions:
I am updating the style guide to clarify this so there is no doubt, and so that Fantomas can hopefully be updated accordingly.
/cc @nojaf @dsyme