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

string interpolation with multi-line string causes literal part to change #1451

Closed
1 of 3 tasks
johlrich opened this issue Feb 13, 2021 · 3 comments · Fixed by #1452
Closed
1 of 3 tasks

string interpolation with multi-line string causes literal part to change #1451

johlrich opened this issue Feb 13, 2021 · 3 comments · Fixed by #1452

Comments

@johlrich
Copy link
Contributor

Issue created from fantomas-online

Code

module ApiPolicy

open Pulumi

let create (discoveryUrl: Input<string>) (aud: Input<string>) (backendId: Input<string>) =
  Output.Format(
    $"""<policies>
  <inbound>
    <validate-jwt header-name="Authorization" failed-validation-httpcode="401" failed-validation-error-message="Unauthorized. Access token is missing or invalid." require-expiration-time="true" require-scheme="Bearer" require-signed-tokens="true">
      <openid-config url="{discoveryUrl}" />
      <required-claims>
        <claim name="aud">
          <value>{aud}</value>
        </claim>
      </required-claims>
    </validate-jwt>
    <set-backend-service backend-id="{backendId}" />
  </inbound>
  <backend>
    <base />
  </backend>
  <outbound>
    <base />
  </outbound>
  <on-error>
    <base />
  </on-error>
</policies>"""
  )

Result

module ApiPolicy

open Pulumi

let create (discoveryUrl: Input<string>) (aud: Input<string>) (backendId: Input<string>) =
    Output.Format(
        $"""<policies>
  <inbound>
    <validate-jwt header-name="Authorization" failed-validation-httpcode="401" failed-validation-error-message="Unauthorized. Access token is missing or invalid." require-expiration-time="true" require-scheme="Bearer" require-signed-tokens="true">
      <openid-config url="{discoveryUrl}" />      <required-claims>        <claim name="aud">          <value>{aud}</value>        </claim>      </required-claims>    </validate-jwt>    <set-backend-service backend-id="{
                                                                                                                                                                                                                                backendId
        }" />  </inbound>  <backend>    <base />  </backend>  <outbound>    <base />  </outbound>  <on-error>    <base />  </on-error></policies>"""
    )

Problem description

The combination of a string interpolation and a multi-line string causes fantomas to both add whitespace to the { } expression as well as change the formatting of the string itself after the first interpolation expression found.

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 02/12/2021 20:07:06 - e016b1c

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 Feb 13, 2021

Hello Jonathan, thank you for reporting this issue.
I believe the issue here is that we are not taking newlines found in the Tokens into account in

let stringContent =
[ yield! (List.map (fun t -> t.Content) stringTokens)
yield interpStringEnd.Content ]
|> String.concat String.Empty

Would you be interested to submit a PR for this?

@johlrich
Copy link
Contributor Author

I would like to try, yes. Thanks for suggesting a place to start.

@nojaf
Copy link
Contributor

nojaf commented Feb 13, 2021

Great to hear, please read our Contribution guidelines first as they contain some other useful tips.
You can also ask some questions via a draft PR if you need any help.
Good luck!

johlrich added a commit to johlrich/fantomas that referenced this issue Feb 13, 2021
New lines were not being preserved when combining the string tokens of an interpolated string expression. If consecutive tokens are on different lines, then we add an additional NewLine in between.

Fixes fsprojects#1451
nojaf added a commit that referenced this issue Feb 16, 2021
* Preserve new lines in string portion of interpolated string

New lines were not being preserved when combining the string tokens of an interpolated string expression. If consecutive tokens are on different lines, then we add an additional NewLine in between.

Fixes #1451

* Minor tweak

Co-authored-by: nojaf <florian.verdonck@outlook.com>
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.

2 participants