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

Incorrect scope chosen for trivia, hence comments lost #2535

Closed
3 tasks
SteveGilham opened this issue Sep 29, 2022 · 1 comment · Fixed by #2560
Closed
3 tasks

Incorrect scope chosen for trivia, hence comments lost #2535

SteveGilham opened this issue Sep 29, 2022 · 1 comment · Fixed by #2560
Labels
bug (soundness) good first issue Long hanging fruit: easy issue to get your feet wet!

Comments

@SteveGilham
Copy link

Issue created from fantomas-online

Code

test
    <@
      result
        .Replace('\r', '\u00FF')
        .Replace('\n', '\u00FF')
        .Replace("\u00FF\u00FF", "\u00FF")
        .Replace("8.12", "8.13") // CRAP score rounding
        .Replace("4.12", "4.13") // CRAP score rounding
        .Trim([| '\u00FF' |]) = expected
        .Replace('\r', '\u00FF')
        .Replace('\n', '\u00FF')
        .Replace("\u00FF\u00FF", "\u00FF")
        .Trim([| '\u00FF' |])
    @>

Result

test
    <@
        result
            .Replace('\r', '\u00FF')
            .Replace('\n', '\u00FF')
            .Replace("\u00FF\u00FF", "\u00FF")
            .Replace("8.12", "8.13")
            .Replace("4.12", "4.13")
            .Trim([| '\u00FF' |]) = expected
            .Replace('\r', '\u00FF')
            .Replace('\n', '\u00FF')
            .Replace("\u00FF\u00FF", "\u00FF")
            .Trim([| '\u00FF' |])
    @>

Problem description

The comment is lost; this is because the element representing the quotation brackets <@ @> is chosen over the element representing the quoted source simply by being first in the list, rather than being the most specific element, despite the comment in findNodeWhereRangeFitsIn.

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.

Options

Fantomas master branch at 2022-09-20T21:08:34Z - 11c2a86

Default Fantomas configuration

@nojaf
Copy link
Contributor

nojaf commented Sep 29, 2022

The operator node in SynExpr.Quote should be ignored and not visited in

| SynExpr.Quote (operator, _, quotedSynExpr, _, range) ->
let continuations: ((TriviaNode list -> TriviaNode list) -> TriviaNode list) list =
[ visit operator; visit quotedSynExpr ]

It is an artificial node constructed by the parser. Removing visit operator resolved the problem.

@nojaf nojaf added bug (soundness) good first issue Long hanging fruit: easy issue to get your feet wet! labels Sep 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug (soundness) good first issue Long hanging fruit: easy issue to get your feet wet!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants