TimLariviere / Fabulous-new

Fabulous v2 - Work in progress
https://timothelariviere.com/Fabulous-new/
Other
41 stars 3 forks source link

Add Fantomas for consistent formatting and check on commit #40

Closed TimLariviere closed 2 years ago

TimLariviere commented 2 years ago

Enable consistent formatting for the whole repo to avoid having IDEs auto-formatting differently between each contributors. This is done by using the default configuration of Fantomas (dotnet tool).

See https://docs.microsoft.com/en-us/dotnet/fsharp/style-guide/formatting for more information

TimLariviere commented 2 years ago

While we wait for https://github.com/fsprojects/fantomas/issues/1985 to be released (v4.6 I believe), I've replaced the new F# 6 exp[idx] with exp.[idx]. Fantomas 4.5 formats it to exp [ idx ] which is interpreted like a function call by F#

TimLariviere commented 2 years ago

Fantomas is not really consistent on extension method either.

Label()
    .centerHorizontal() // Here it follows method convention of no space between name and parens
    .centerVertical () // Here it follows function convention

I would have expected extension methods to follow the method convention centerHorizontal().

TimLariviere commented 2 years ago

Let's merge this PR only after #33, #36, and #37 to avoid conflicts

twop commented 2 years ago

Btw what about {} pairs?

I do prefer to have them on separate lines because I use "copy line above"/ "copy line below" a lot and the default styling was messing with that badly. The only solution I could find is to use this formatting:

let obj = 
   {
      FieldA = 1
      Field2 = 1
   }

or example from code:

member inline _.Combine(a: Content<'msg>, b: Content<'msg>) : Content<'msg> =
            {
                Widgets = MutStackArray1.combineMut(&a.Widgets, b.Widgets)
            }

It it kinda esthetically annoying, but I found it to be a better compromise for my code editing habits.

Thought on this? Do you have a strong opinion?

TimLariviere commented 2 years ago

Personally, I do prefer the recommended style for { }. Find it more readable, instead of having empty lines with just brackets.

Also following the recommended guideline is better for 2 things:

twop commented 2 years ago

Personally, I do prefer the recommended style for { }. Find it more readable, instead of having empty lines with just brackets.

Also following the recommended guideline is better for 2 things:

  • Our samples/templates will be used by users, so we need to follow the guideline
  • New contributors (and occasional source code readers) will be less confused if we stick to the guideline

Agreed, oh well. I guess, I will endure the pain :)