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

Comment above single parameter in brackets breaks code due to wrong indentation #2594

Closed
1 of 3 tasks
stefan-schweiger opened this issue Oct 20, 2022 · 2 comments · Fixed by #2641
Closed
1 of 3 tasks

Comments

@stefan-schweiger
Copy link
Contributor

stefan-schweiger commented Oct 20, 2022

Issue created from fantomas-online

Code

let doSomething _ _ = ()

let test1 param =
    doSomething
        // my comment
        (param)

let test2 param =
    doSomething
        // my comment
        (param)
        (param)

Result

let doSomething _ _ = ()

let test1 param =
    doSomething
    // my comment
    (param)

let test2 param =
    doSomething
        // my comment
        (param)
        (param)

Problem description

If there is a comment above a single parameter which is in brackets the resulting code has the wrong indentation and breaks. It works fine if multiple parameters are supplied.

I know the sample is pretty simple and you could just remove the brackets. But the same thing happens for parameters which are functions with applied parameters.

Extra information

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

Options

Fantomas main branch at 2022-10-19T15:02:12Z - 25cb8d5

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?

@nojaf
Copy link
Contributor

nojaf commented Oct 24, 2022

Hello, some context on this one:
When a tupled function invocation is multiline, it will write something like fn (a,b,c) to

fn (
    a,
    b,
    c
)

(style guide)
The code comment between fn and ( makes the code follow the multiline path.
When Fantomas changes the indentation, it only kicks in when the next newline is added.

So what happens here is:

doSomething
// my comment
(

the indentation will kick in on the following line, but as (param) is too short it will never get to that point.
(Example where it does kick in).

If the parentheses have trivia, we probably want to indent right before the opening parenthesis.
One could of course argue if there needs to be any indentation at all (I mean between the parentheses and the argument expr), but that would be a matter to discuss in the F# style guide.

@nojaf
Copy link
Contributor

nojaf commented Jan 2, 2023

Fix available in v5.2.0-beta-001

@nojaf nojaf closed this as completed Jan 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants