-
-
Notifications
You must be signed in to change notification settings - Fork 193
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
Strings containing spaces at end of line change meaning #1941
Comments
Note that as a workaround, normal (non-triple-quote) strings in F# can use "\032" as a space character Triple quote strings cause more problems This came up in this change in a test for FSharp.Formatting |
I found another case where fantomas formatting causes an FSharp.Formatting test to fail for the same reason Here a test is testing the exact output of formatting, and the test result expects to see a space at end of line on one line. Triple-quote strings are used because they're very convenient for such cases |
(None of these recent bug reports are blocking, since I can adjust FSharp.Formatting either tests or behaviour, but they are interesting cases for fantomas) |
* apply fantomas formatting * workaround formatting bugs * address issues arising from fsprojects/fantomas#1941 * simplify code
Interesting, I believe there might be an issue when processing the F# string tokens. The last token does not contain any content (only three spaces) so perhaps it is not picked up in TokenParser for this reason. fantomas/src/Fantomas/TokenParser.fs Lines 589 to 606 in 8f00ea8
|
I found the culprit: fantomas/src/Fantomas/Context.fs Lines 319 to 326 in 31fc949
We trim each line here. This will be a bit tricky to fix as we lost all meaning of each line by that point. Doing the trimming earlier in fantomas/src/Fantomas/Context.fs Lines 94 to 106 in 31fc949
is also not that simple as you don't know which @jindraivanek any thoughts? |
If a multi-literal string contains a space at the end of a line then it changes semantic meaning when formatted.
This seems wrong, since Fantomas should never change meaning of source code, but it may be considered acceptable in the balance of things, especially if C# and other languages would trim spaces even in strings (as a general editor setting)
In the example below there are spaces at the end of the line within the string
Issue created from fantomas-online
Code
Result
The value of
s
has changedProblem description
Please describe here the Fantomas problem you encountered.
Check out our Contribution Guidelines.
Extra information
Options
Fantomas 4.6 branch at 10/31/2021 14:52:39 - 420ef5c
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?
The text was updated successfully, but these errors were encountered: