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

Stroustrup: Two lists given directly as parameters, break code #2681

Closed
1 of 3 tasks
panmona opened this issue Jan 4, 2023 · 3 comments · Fixed by #2684
Closed
1 of 3 tasks

Stroustrup: Two lists given directly as parameters, break code #2681

panmona opened this issue Jan 4, 2023 · 3 comments · Fixed by #2684

Comments

@panmona
Copy link
Contributor

panmona commented Jan 4, 2023

Issue created from fantomas-online

Code

Layout.twoColumnLayoutWithStyles
    styles
    [
        element1 longParameterName1 param2 param3
        element1 longParameterName1 param2 param3
    ] 
    [
        element1 longParameterName1 param2 param3
        element1 longParameterName1 param2 param3
    ]

Result

Layout.twoColumnLayoutWithStyles
    styles[element1 longParameterName1 param2 param3
           element1 longParameterName1 param2 param3]
    [
        element1 longParameterName1 param2 param3
        element1 longParameterName1 param2 param3
    ]

Problem description

When the items in the first list are big enough, it should add line breaks. But a space is removed between the first parameter and the first list. This is unfortunately invalid code.

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 2023-01-04T10:51:25Z - 1eb5725

    { config with
                MultilineBracketStyle = experimental_stroustrup }

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 Jan 4, 2023

Hello, thank you for raising this issue.

I took a quick look and this doesn't appear to be a regression due to project Dallas. (Sample)

I believe the problem will be around:

+> col sepSpace node.SequentialExpr genExpr
+> genExpr node.FirstArrayOrList

onlyIfNot node.SequentialExpr.IsEmpty sepSpace might be required between those lines.
Haven't tested this.

Are you interested in submitting a PR?

@josh-degraw
Copy link
Contributor

I just applied that and while it fixes the invalid code problem, it brought up another question for me of how the elmish syntax is kind of tangential to stroustrup.

That change results in output like this:

Layout.twoColumnLayoutWithStyles styles [
    element1 longParameterName1 param2 param3
    element1 longParameterName1 param2 param3
] [
    element1 longParameterName1 param2 param3
    element1 longParameterName1 param2 param3
]

which matches elmish style, and technically matches stroustrup alignment, but I think this would make sense to be handled in a separate configuration option (e.g. elmish_list_style or something), especially because I could see some people wanting to use elmish style for situations like this but would prefer to use Aligned or Cramped for other situations (inversely, I would personally prefer the way OP had the code originally even when I'd prefer stroustrup for most situations).

I can PR this change as is but I thought I'd bring it up for discussion if you're open to discussing it separately.

@nojaf
Copy link
Contributor

nojaf commented Jan 4, 2023

I can PR this change as is but I thought I'd bring it up for discussion if you're open to discussing it separately.

Thanks for the PR! I've had a similar thought on extracting this to its own setting.
We can discuss this separately.

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.

3 participants