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

else if handling misplaces directive located between the keywords #2772

Open
3 tasks done
majocha opened this issue Feb 15, 2023 · 2 comments
Open
3 tasks done

else if handling misplaces directive located between the keywords #2772

majocha opened this issue Feb 15, 2023 · 2 comments

Comments

@majocha
Copy link
Contributor

majocha commented Feb 15, 2023

Issue created from fantomas-online

Code

if true then 0
else
#if FOO
    if false then 1
    else
#endif
        2

Result

if true then
    0
else if
#if FOO

    false
then
    1
else
#endif
    2

Problem description

Directive before if moves after it, changing semantics and/or making the code invalid.

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.

It came on my mind to test this while trying to tackle #2752. I'm not sure if this one will also make a good first issue :)

Options

Fantomas main branch at 2023-02-04T13:46:10Z - 9f769d8

    { config with
                KeepMaxNumberOfBlankLines = 1 }

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 Feb 16, 2023

Hello, thank you for reporting this issue.

The input here is quite the departure from what the style guide recommends, and that can lead to the bug you see here.

If the code follows the guide better, for example, it is able to correctly format it. This might be the workaround you can use in your production code.

I'm afraid I can't really point you in any direction for this one. From a technical standpoint, there is no relation between the #if FOO and #endif so I don't really know what can be done about this.

@majocha
Copy link
Contributor Author

majocha commented Feb 16, 2023

Hi, @nojaf.
Thanks for the swift and detailed response.
This is a contrived example I did, so I probably shouldn't tick "breaks my code" when what I had on mind is "it could break code".

Now is I look at it I notice this should probably be caught by isValidFSharpCode because with the define unset it becomes:

if true then
    0
else if
    2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants