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

Idempotency problem when using lower MaxLineLength than default and fantomas needs to split lines #2176

Closed
3 tasks
knocte opened this issue Apr 1, 2022 · 2 comments · Fixed by #2190
Closed
3 tasks

Comments

@knocte
Copy link
Contributor

knocte commented Apr 1, 2022

Issue created from fantomas-online

Formatted code

namespace FSX.Infrastructure

module Unix =

    let GrabTheFirstStringBeforeTheFirstColon (lines: seq<string>) =
        seq {
            for line in lines do
                yield (line.Split([| ":" |], StringSplitOptions.RemoveEmptyEntries)).[0]
        }

Reformatted code

namespace FSX.Infrastructure

module Unix =

    let GrabTheFirstStringBeforeTheFirstColon (lines: seq<string>) =
        seq {
            for line in lines do
                yield
                    ((line.Split(
                        [| ":" |],
                        StringSplitOptions.RemoveEmptyEntries
                    ))).[0]
        }

Expected result

namespace FSX.Infrastructure

module Unix =

    let GrabTheFirstStringBeforeTheFirstColon (lines: seq<string>) =
        seq {
            for line in lines do
                yield
                    (line.Split(
                        [| ":" |],
                        StringSplitOptions.RemoveEmptyEntries
                    )).[0]
        }

Problem description

Fantomas was not able to produce the same code after reformatting the result (note, the bug doesn't happen if MaxLineLength=120), adding unnecessary parentheses.

Extra information

  • The formatted result breaks by code.
  • The formatted result gives compiler warnings.
  • I or my company would be willing to help fix this.

Options

Fantomas master branch at 2022-03-29T09:12:14Z - 8f2ab14

    { config with
                MaxLineLength = 80 }

Did you know that you can ignore files when formatting from fantomas-tool or the FAKE targets by using a .fantomasignore file?

@nojaf
Copy link
Contributor

nojaf commented Apr 1, 2022

The additional introduced parentheses are probably part of a last resort measure to produce valid code.
I agree this is a bug, I'm going to mark it stylistic but it can be fixed against the master branch.

@knocte
Copy link
Contributor Author

knocte commented Apr 5, 2022

I'm going to mark it stylistic

AFAIU, idempotency problems are never marked as stylistic. Please note that this is not just superflous addition of parentheses: if you run fantomas 3 times, 3 pairs of parentheses are added.

janus added a commit to janus/fantomas that referenced this issue Apr 6, 2022
nojaf pushed a commit to janus/fantomas that referenced this issue Apr 6, 2022
janus added a commit to janus/fantomas that referenced this issue Apr 6, 2022
janus added a commit to janus/fantomas that referenced this issue Apr 6, 2022
nojaf pushed a commit that referenced this issue Apr 6, 2022
jindraivanek pushed a commit to jindraivanek/fantomas that referenced this issue Apr 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants