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

Excessive line breaking #43

Closed
ovatsus opened this issue Jul 1, 2013 · 8 comments
Closed

Excessive line breaking #43

ovatsus opened this issue Jul 1, 2013 · 8 comments

Comments

@ovatsus
Copy link

ovatsus commented Jul 1, 2013

I have line breaks set at 120, and I had this line:

              let details = cells.[4] |> element "a" |> attr "href"

which ended at line 79, but it was still broke down like this:

              let details = 
                  cells.[4]
                  |> element "a"
                  |> attr "href"

I actually don't mind in this case, but just posted the issue to make sure this was intentional and not a bug, as it doesn't seem consistent because fantomas does the opposite for functions. I had this:

    let radians2Dist radians radius = 
        radians * radius
    let degrees2Dist degrees radius = 
        radians2Dist (toRadians degrees) radius

and it was converted to this:

    let radians2Dist radians radius = radians * radius
    let degrees2Dist degrees radius = radians2Dist (toRadians degrees) radius
@dungpa
Copy link
Contributor

dungpa commented Jul 1, 2013

It's intentional.

Any expression containing |> is treated as a multiline expression and is broken around |> for aestheticity.

The last two examples consist of one-liner expressions.

@7sharp9
Copy link
Member

7sharp9 commented Jul 2, 2013

I would only drop a |> down to the next line if the line was too long, or maybe if there was more than two pipes. Does a reverse pipe get formatted the same?

@dungpa
Copy link
Contributor

dungpa commented Jul 2, 2013

@7sharp9 Reverse pipe is treated as one-liner.

Since <| has relatively low precedence, you will not see their consecutive occurrences often.

@ghost
Copy link

ghost commented Jul 2, 2013

It does look like the line breaking is a bit excessive for some quite common uses of |>. For example:

let ``update length 3``() =
    (((len3 |> update 0 "cc"|> lookup 0) = "cc") && ((len3 |> update 1 "bb"|> lookup 1) = "bb") 
    && ((len3 |> update 2 "aa"|> lookup 2) = "aa")) |> should equal true

becomes

let ``update length 3``() = 
    (((len3
       |> update 0 "cc"
       |> lookup 0) = "cc") && ((len3
                                 |> update 1 "bb"
                                 |> lookup 1) = "bb") && ((len3
                                                           |> update 2 "aa"
                                                           |> lookup 2) = "aa"))
    |> should equal true

and

let len7 = empty |> cons "a" |> cons "b" |> cons "c" |> cons "d" |> cons "e" |> cons "f" |> cons "g"

becomes

let len7 = 
    empty
    |> cons "a"
    |> cons "b"
    |> cons "c"
    |> cons "d"
    |> cons "e"
    |> cons "f"
    |> cons "g"

@dungpa
Copy link
Contributor

dungpa commented Jul 8, 2013

These line breakings are indeed excessive.

It would be nice to add a few common patterns to print |> as inline expressions. What are your suggestions?

@s-trooper
Copy link
Contributor

Hello, i have more general issue but with same Title.

Hi,
I would like to have an option to disable line breaking and line removing on code formatting.
In my case I need empty lines for readability purposes and disabling auto formating would
give me more freedom to control the codeset, i.e to control my record, pipe and list style
in my own way.

Thank you in advance!

@nojaf
Copy link
Contributor

nojaf commented Jul 12, 2019

I need empty lines for readability purposes

The situation has improved in #434, please create a new issue with additional suggestions if necessary.

@OlegAlexander
Copy link

OlegAlexander commented Aug 30, 2022

Hello. I also feel that Fantomas adds too many line breaks by default. Thankfully, I'm able to control this with the Max... settings. However, I can't find a way to control the following examples:

Code:

open System open System.IO

Result:

open System
open System.IO

Code:

type JpgDir = string type TifDir = string

Result:

type JpgDir = string
type TifDir = string

Code:

module A = Array;; module L = List;;

Result:

module A = Array
module L = List

Code:

let trace x = printfn "%A" x; x

Result:

let trace x =
    printfn "%A" x
    x

Code:

let tryParseInt s = try Some (int s) with | :? FormatException -> None

Result:

let tryParseInt s =
    try
        Some(int s)
    with :? FormatException ->
        None

Code:

let boolToInt x = match x with | true -> 1 | false -> 0

let boolToInt' = function | true -> 1 | false -> 0

Result:

let boolToInt x =
    match x with
    | true -> 1
    | false -> 0

let boolToInt' =
    function
    | true -> 1
    | false -> 0

Of these examples--most of which I realize are not idiomatic F#!--the last one with the pattern match is my highest priority. If you'd like, I'll be happy to open a new issue just for the pattern match example. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants