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

Breaking method chain in the middle of an if statement causes offside error #1712

Closed
2 of 3 tasks
Smaug123 opened this issue May 10, 2021 · 4 comments · Fixed by #1736
Closed
2 of 3 tasks

Breaking method chain in the middle of an if statement causes offside error #1712

Smaug123 opened this issue May 10, 2021 · 4 comments · Fixed by #1736

Comments

@Smaug123
Copy link
Contributor

Issue created from fantomas-online

Code

module Foo =
    let bar =
        if Regex("long long long long long long long long long").Match(s).Success then
            None
        else Some "hi"

Result

module Foo =
    let bar =
        if Regex(
            "long long long long long long long long long"
        )
            .Match(
            s
        )
            .Success then
            None
        else
            Some "hi"

Problem description

Not really sure what the best format here would be. Maybe:

if Regex("long long long…")
    .Match(s)
    .Success then
    None
else
    Some "hi"

assuming that actually compiles.

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 at 05/09/2021 13:45:10 - f10b822

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 May 18, 2021

Maybe be can go with

module Foo =
    let bar =
        if
            Regex(
                "long long long long long long long long long"
            )
                .Match(
                s
            )
                .Success
        then
            None
        else
            Some "hi"

as suggested in the MS style guide here.

What do you think? It would be easy to get around those offset errors that way.

@Smaug123
Copy link
Contributor Author

Oof, I find that extremely ugly, I'm afraid! @TobyShaw I don't suppose you have any cunning ideas here?

@nojaf
Copy link
Contributor

nojaf commented May 19, 2021

Well I feel like there are two parts to this:

  1. How Fantomas deals with the expression
  2. What Fantomas should do in case the if expression is long or funky.

As for 1:

Regex(
    "long long long long long long long long long"
)
    .Match(s)
    .Success

might be an option.

When it comes to 2, I do like the

if
    longExpression
then
    // ...

style, it nicely highlights that you may wanted to go with a intermediate let binding instead.
And it also has a bit of rhyme with try/with or match/with, though indeed quite far fetched.
Any chance that helps? I'm open for feedback here, life is easier with my proposal for 2 as it plays better with the offset rules.

@Smaug123
Copy link
Contributor Author

I guess in real life an expression that is long and complex enough to format this way is going to get changed at review time.

I think I agree with both your suggestions 1 and 2; it's just the implied combination that makes me sad :P perhaps it's fine, though, and we'll just have an informal rule saying "you should never write code that falls into this case".

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