-
-
Notifications
You must be signed in to change notification settings - Fork 193
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
Indentation of Else block #1361
Comments
Note that I'm pretty confident that Fantomas is already correct on if a then
b
else
c I'm specifically only talking about cases where the user has explicitly chosen not to indent. |
The same is true of |
No, please. I precisely want to use fantomas to catch this kind of practices and fix them to be consistent. To me, indenting to the left the way you prefer, is completely unreadable and confusing. |
Well, it gets more unreadable and confusing when your code looks like: if a then
b
else
doThings()
if c then
d
else
doThings2()
if e then
f
else
doThings3()
… This arises when using railway-oriented programming and |
Another readability workaround is extract more code into more small functions. |
It's sad to break up a continuous flow of error-handling logic into arbitrary chunks purely to satisfy the formatter; I discussed that option with my team and (regardless of the various opinions on whether it's fine to unindent My team broadly agrees that if you're using We can work around this in code using |
Hey Patrick, thanks for bringing this up. Fantomas currently does not preserve anything from code style from the original code. So to follow that principle, we somehow need some sort of rule and a setting to get to preferred behavior. if a then b
else
c For example, if the length of |
I still haven't come up with a rule, but here's another example which comes up a lot in our internal code: open Library
type RunMode =
| Dry
| Wet
let main argv =
let args = parse argv
let instructions = Library.foo args
match args.DryRun with
| RunMode.Dry ->
printfn "Would execute actions, but --dry-run was supplied: %+A" instructions
0
| RunMode.Wet ->
// proceed with main method
let output = Library.execute instructions
// do more stuff
0 It's really sad to have to wrap all the real main-method logic up into another function just to control the indentation here; it adds a layer of indirection and mental overhead for no benefit. Splitting up the function doesn't increase readability in this case. |
As there is more information these days about the keywords and tokens, I'd like to revisit this to request and maybe go for a simpler approach. If the setting is true and the original code already didn't indent the let developer A wrote =
if a then
b
else
c // long expr
let developer B wrote =
if a then
b
else
c // long expr What do you think @Smaug123? |
@nojaf, I think allowing certain settings that support leniency towards individual programmer's preference is a good way to go. I personally find code that uses this approach utterly confusing and unreadable (if you have a pyramid of doom, there's probably something you should refactor). But having a setting that allows a slightly less deep pyramid of doom in certain scenarios, at the user's discretion, is probably a good thing for some companies/policies. I prefer it over the current situation of having a "forced style for all |
I do not, the downfall of this setting is that developer A made a choice that developer B may not have made. Fantomas currently outputs a consistent story regardless of which developer wrote the code. This setting does not adhere to that philosophy. The only reason we have this setting is at the request of our enterprise sponsor G-Research. |
Does architecture allow to disable a particular rule processing not to handle ifs at all? |
Thanks for the explanation, I see your point. Consistency guarantees trump individual preferences. |
Issue created from fantomas-online
Code
Result
Problem description
I didn't realise this would be a problem for us, but sadly we have several places where we kind of rely on the ability to
if
/then
/else
without indentation. In functions with a lot of different possible outcomes, the code really marches off to the right unless we stick theelse
at the same indentation as the parent.That is, because the original code had the
else
block unindented, it would be great if the output also had theelse
block unindented:I definitely understand why Fantomas does what it does, but do you think it would be reasonable to respect the user's choice not to indent
else
blocks?Extra information
Options
Fantomas Master at 01/09/2021 08:58:25 - ca42f0d
Default Fantomas configuration
Did you know that you can ignore files when formatting from fantomas-tool or the FAKE targets by using a .fantomasignore file?
The text was updated successfully, but these errors were encountered: