-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
F# style guide question - multiline expression in match or if expression #26507
Comments
Long is multi-line (but does it matter? the
No, I don't think so - I don't agree with the extra line added in the style guide |
Well, if long = multiline then the example should have the expression on the next line one scoped indented from the
Which kinda contradicts the long = multiline right? Or do you mean something else? So where does that leave I'm well aware I'm asking difficult questions here 😅, but under which conditions would the following apply: if a then
b
// what rules should apply to `a` to become
if
a then
b And are these rules the same for match a with
| _ -> b
// what rules should apply to `a` to become
match
a
with
| _ -> () One rule I can think of is when |
I personally think we should never be inserting the newlines, so always if multi
line then
b
match multi
line with
| _ -> () I guess one indent from But I don't mind too much. I think the |
I do use if long-thing &&
another-long-thing &&
another-long-thing &&
another-long-thing then in the compiler. I don't think this should get any extra new-lines |
Which to me sounds reasonable but unfortunately contradicts https://github.com/dotnet/docs/pull/26294/files#diff-5583236f005ad44753c6945d4312c09cbd439fb251f9a01db543048fe51d284bR77-R84 |
Yes that example isn't demonstrating the rule bring discussed is it? I don't think it should be in the guide, I didn't think enough before merging it. The formattings above don't suffer from renaming problems AFAICS? Let's remove those examples from the guide? |
Sounds good to me, however, I may want to add an explicit section to cover that the specific cause is not a vanity alignment. On a side note, could we perhaps introduce the policy that all PR's for the style guide need a discussion in an issue first? Lastly, I do want to give @knocte a chance to reply to all of this as he made the previous PR and has an interest in this. |
Wait a second. So then you don't agree with the principles behind this past (&closed) issue?: #21487 Because this:
actually means vanity indentation. Let's see the example again:
Am I seeing what everyone is seeing? a 3-space indentation? Are we out of our minds here? :) |
I'll review those discussions carefully and have a think about this. I sort of missed the significance of that dicussion and didn't participate in it.
Painful, it's true. That said, "Avoid vanity (e.g. 3-space) indentation" is certainly not an established principle in the style guide - it's not actually mentioned anywhere besides in that PR and I think there are existing samples in the guide that break this principle. It's quite a big thing to be adding to the guide and for all Fantomas formatting defaults. |
@knocte Do you particularly care about the positioning of the |
Well, I kinda care, but agree it might be a separate issue. Thing is, while I would like to have a consistent view about where to put then and with, I notice the following:
Example:
Example:
AFAIU having two levels of indentation in an if-then block seems overkill, that's why in this case I prefer the then in the same line as the if. But let's go back to the most important topic at hand: 3-spaces indentation. Cannot this code...:
...just use a standard indentation level if the line has to be split? like this:
This compiles, right? Sure, I understand that it wouldn't be consistent with the following match case:
However, IMO it's well justified simply because the word |
I'm coming around to the point-of-view that the default formatting and style-guide recommendation for multi-line inputs to match
directoryRouter.GetIdentity ()
|> self.ServerDescriptors.TryFind
with
| None ->
CircuitNodeDetail.FastCreate
| Some serverDescriptor ->
self.ConvertToCircuitNodeDetail serverDescriptor Is there any reason not to align the |
Yes, it doesn't compile (gives error FS0010). Not sure if this compiles with newer F# though. |
Yes it compiles with F# 6 |
For if-then-else, it is entirely consisitent to do this: if
long-thing &&
another-long-thing &&
another-long-thing &&
another-long-thing
then though
I'm trying to get a read on what's "normal" for other languages. It seems C/C# auto-formatting simply don't do any formatting of boolean logic? For JS/TS, prettier does similar to the above, e.g. here |
Hello @dsyme ,
Following up on https://github.com/fsprojects/fantomas/issues/1915, I'd like to verify how you see the formatting of long (say multiline) expressions inside
if/then/else
ofmatch/with
.I have two questions here:
if/then
as they are formatch/with
? I always assumed so to remain consistent.if/then/else
mentionWhat is long? Would any multiline expression fit the bill here?
Example
Should it be
?
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
The text was updated successfully, but these errors were encountered: