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

MultilineBlockBracketsOnSameColumn not working properly when calling base constructors #852

Closed
knocte opened this issue May 21, 2020 · 11 comments · Fixed by #854
Closed

Comments

@knocte
Copy link
Contributor

knocte commented May 21, 2020

Issue created from fantomas-online

Please describe here fantomas problem you encountered

Code

type ServerCannotBeResolvedException =
    inherit CommunicationUnsuccessfulException

    new(message) =
        { inherit CommunicationUnsuccessfulException(message) }

Result

With MultilineBlockBracketsOnSameColumn disabled:

type ServerCannotBeResolvedException =
    inherit CommunicationUnsuccessfulException

    new(message) =
        { inherit CommunicationUnsuccessfulException(message) }

With MultilineBlockBracketsOnSameColumn enabled:

type ServerCannotBeResolvedException =
    inherit CommunicationUnsuccessfulException

    new(message) =
        { inherit CommunicationUnsuccessfulException(message)

        }

Expected results (with MultilineBlockBracketsOnSameColumn enabled):

type ServerCannotBeResolvedException =
    inherit CommunicationUnsuccessfulException

    new(message) =
        {
            inherit CommunicationUnsuccessfulException(message)
        }

Options

Fantomas Next - 4.0.0-alpha-001-1/1/1990

Name Value
IndentSpaceNum 4
PageWidth 120
SemicolonAtEndOfLine false
SpaceBeforeParameter true
SpaceBeforeLowercaseInvocation true
SpaceBeforeUppercaseInvocation false
SpaceBeforeClassConstructor false
SpaceBeforeMember false
SpaceBeforeColon false
SpaceAfterComma true
SpaceBeforeSemicolon false
SpaceAfterSemicolon true
IndentOnTryWith false
SpaceAroundDelimiter true
MaxIfThenElseShortWidth 40
MaxInfixOperatorExpression 50
MaxRecordWidth 40
MaxArrayOrListWidth 40
MaxLetBindingWidth 40
MultilineBlockBracketsOnSameColumn true
NewlineBetweenTypeDefinitionAndMembers false
KeepIfThenInSameLine false
StrictMode false
@Bobface
Copy link
Contributor

Bobface commented May 21, 2020

@nojaf In the tests I can see that sometimes the first element of a record is expected to be on the same line as the opening bracket. For example:

[<Test>]
let ``update record with standard indent`` () =
formatSourceString false "let expected = { ThisIsAThing.Empty with TheNewValue = 1 }" config
|> prepend newline
|> should equal """
let expected =
{ ThisIsAThing.Empty with
TheNewValue = 1
}
"""

Is this expected? If so, could you clarify in which cases this behaviour is expected?

@knocte
Copy link
Contributor Author

knocte commented May 21, 2020

Remembering the github issue that inspired the MultilineBlockBracketsOnSameColumn setting, I'd say that any person that enables this expects always to have things like:

StuffHere
    {
        MoreStuffHere...

So, with this setting enabled, nothing should be in the same line as the opening/closing braces.

@nojaf
Copy link
Contributor

nojaf commented May 21, 2020

@knocte this is by design. See unit test .

In alignment with how update records work.

@knocte
Copy link
Contributor Author

knocte commented May 21, 2020

@knocte this is by design. See unit test .
In alignment with how update records work.

Those unit tests and the update records cases have more lines. Look at my original testcase, it's just an inherit line, not more lines. If anything, it should put the closing brace in the same line.

So, either this expected result:

        {
            inherit CommunicationUnsuccessfulException(message)
        }

or this one:

        { inherit CommunicationUnsuccessfulException(message) }

but not this:

        { inherit CommunicationUnsuccessfulException(message)

        }

@nojaf
Copy link
Contributor

nojaf commented May 21, 2020

{ inherit CommunicationUnsuccessfulException(message) } is 55 characters long so that crosses the boundaries of the MaxRecordWidth (40 in your report).
Leading to the current style (where { and inherit are on the same line.

@knocte
Copy link
Contributor Author

knocte commented May 22, 2020

so that crosses the boundaries of the MaxRecordWidth (40 in your report).

But this is not a record! I use short MaxRecordWidth (in fact I set it to 0 in my project) because I don't like the use of ; to separate record members, but we're not talking about the same thing here.

Leading to the current style (where { and inherit are on the same line.

I guess you actually meant where } is on a separate line. I don't have much issue with the opening brace so long as I don't see that weird way of ending it. To me, fantomas should behave in a way that a sane developer would behave, a way which could be possible to encode in a code-style guide. But telling anyone to write this...:

        { inherit CommunicationUnsuccessfulException(message)

        }

...doesn't strike me as something sane at all. I hope you agree that we need to fix it (even if we disagree on the way to fix it).

@nojaf
Copy link
Contributor

nojaf commented May 22, 2020

But this is not a record!

It actually is from AST perspective.

image

I guess we can add an exception when the inherit part is not followed by any record field names that we just go of the single line formatting.

@Bobface
Copy link
Contributor

Bobface commented May 25, 2020

@nojaf How about if we use the Context to check if we are inside a new and apply special rules if that's the case?

@nojaf
Copy link
Contributor

nojaf commented May 25, 2020

@Bobface you don't really need the Context here, the information is all available in the AST.

The empty list on line 57 are the record fields I believe (matching xs here)
You can do a check over there I think.

@Bobface
Copy link
Contributor

Bobface commented May 25, 2020

@nojaf AFAIK there can also be values declared even when inherit-ing:

{
    inherit CommunicationUnsuccessfulException(message)
    SomeA = ThingA
    SomeB = ThingB
    ...
}

This would be matched as regular record again as the empty list in line 57 would (I believe?) not be empty anymore.

@nojaf
Copy link
Contributor

nojaf commented May 25, 2020

When empty I would go for:

{ inherit CommunicationUnsuccessfulException(message) }

when not empty:

{
    inherit CommunicationUnsuccessfulException(message)
    SomeA = ThingA
    SomeB = ThingB
}

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

Successfully merging a pull request may close this issue.

3 participants