Skip to content
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

Start using fantomas to validate code submissions with CI #581

Closed
64J0 opened this issue Mar 15, 2024 · 6 comments
Closed

Start using fantomas to validate code submissions with CI #581

64J0 opened this issue Mar 15, 2024 · 6 comments
Assignees

Comments

@64J0
Copy link
Member

64J0 commented Mar 15, 2024

Description:

In order to keep the code properly formatted we could leverage fantomas, by running this tool on CI.

@reinux
Copy link

reinux commented Mar 26, 2024

Is there a way to have it respect blank lines? I tend not to use Fantomas because it didn't respect paragraph breaks last time I checked.

@64J0
Copy link
Member Author

64J0 commented Mar 27, 2024

I did not get your point @reinux. You mention in comments, right?

In my experience it does not touch comments, but just to make sure, can you please provide an example for what you have in mind?

Other than that, considering that this has the potential to influence all the codebase, I think it's worth adding it only to the samples along with the tests first.

@reinux
Copy link

reinux commented Mar 27, 2024

Stuff like this:

let arrange itemWidth (getSize: 'i -> int * int) (canvasWidth, canvasHeight) (items: 'i list) : Rect list =
  let rec loop (left, top) bottom items rects =
    match items with
    | x :: xs ->
      let width, height = getSize x
      let ratio = (float width / float height)
      let width, height = itemWidth, int (float height / ratio)
                          // inserted empty line
      if top + height > canvasHeight then
        rects

      elif left + width > canvasWidth then
        if bottom + height > canvasHeight then
          rects
        else
          let rect =
            { left = 0
              top = bottom
              width = width
              height = height }
                          // inserted empty line
          loop (0, bottom) (bottom + height) xs (rect :: rects)

      else
        let rect =
          { left = left
            top = top
            width = width
            height = height }
                          // inserted empty line
        loop (left + rect.left, top) (max bottom (top + rect.height)) xs (rect :: rects)
    | [] -> rects

  loop (0, 0) 0 items [] |> List.rev

I have my code arranged into paragraphs that indicate conceptually related code, but Fantomas places blank lines between let bindings and return expressions, which makes the deliberate paragraph groupings harder to spot.

Sorry, I didn't mean for this to be a Fantomas question on the Giraffe repo, but I was just thinking that it would be nice to configure that (if possible) if Giraffe gets the Fantomas treatment.

@64J0
Copy link
Member Author

64J0 commented Mar 28, 2024

Got it now, thanks for the clarification. I'm not sure if it's possible but I'll take a look.

@64J0
Copy link
Member Author

64J0 commented Apr 2, 2024

We can configure Fantomas using some .editorconfig commands: https://fsprojects.github.io/fantomas/docs/end-users/Configuration.html.

@TheAngryByrd
Copy link
Member

Here are my personal tastes for Fantomas with editorconfig

@nojaf nojaf mentioned this issue Sep 5, 2024
@64J0 64J0 closed this as completed Sep 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants