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

Required backslash removed in string interpolation #1344

Closed
1 of 3 tasks
suside opened this issue Jan 4, 2021 · 3 comments
Closed
1 of 3 tasks

Required backslash removed in string interpolation #1344

suside opened this issue Jan 4, 2021 · 3 comments

Comments

@suside
Copy link
Contributor

suside commented Jan 4, 2021

Issue created from fantomas-online

Code

$"INSERT INTO \"{tableName}\" {colNames} VALUES {values}"

Result

$"INSERT INTO "{tableName}" {colNames} VALUES {values}"

Problem description

Interestingly, formating this does not remove \:

$"INSERT INTO \"{tableName}\" {colNames} VALUES"

so it's like the third variable is causing the error?

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 12/26/2020 15:00:23 - 76fa31e

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 Jan 8, 2021

Hello @suside, thank you for reporting this issue.
This looks like a Trivia issue somewhere around

let stringsFromTrivia =

Would you be interested in submitting a PR?

@suside
Copy link
Contributor Author

suside commented Jan 8, 2021

Hi @nojaf
I took a look but unfortunately I don't know what's wrong there 😕

Failing test case:

[<Test>]
let ``backslash in interpolation, issue 1344`` () =
    formatSourceString
        false """
$"\"{bar}\" {1} {2}"
"""
        config
    |> prepend newline
    |> should
        equal """
$"\"{bar}\" {1} {2}"
"""

@nojaf
Copy link
Contributor

nojaf commented Jan 8, 2021

I believe the active pattern

let private (|InterpStringEndToken|_|) token =
if token.TokenInfo.TokenName = "INTERP_STRING_END" then
Some token
else
None

Needs to be changed to:

let private (|InterpStringEndOrPartToken|_|) token =
    if token.TokenInfo.TokenName = "INTERP_STRING_END"
       || token.TokenInfo.TokenName = "INTERP_STRING_PART" then
        Some token
    else
        None

In order to capture all interpolated strings as trivia.

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