fsprojects / fantomas

FSharp source code formatter
https://fsprojects.github.io/fantomas
Other
772 stars 194 forks source link

Adding parentheses around expressions can lead to incorrect indentation #385

Closed SteveGilham closed 5 years ago

SteveGilham commented 5 years ago

Description

Fantomas 0.9.1 command line --indent 2 --pageWidth 90

before

      let line =
        XElement(X "line", XAttribute(X "number", s.Attribute(X "sl").Value),
                 XAttribute(X "hits", vx),
                 XAttribute(X "branch",
                            if bec = 0 then "false"
                            else "true"))

after

      let line = // line 167
        XElement(X "line", XAttribute(X "number", s.Attribute(X "sl").Value),
                 XAttribute(X "hits", vx),
                 XAttribute(X "branch", (
                            if bec = 0 then "false"
                            else "true")))

The extra parentheses around the if expression lead to

[whatever].fs(171,29): error FS0058: Possible incorrect indentation: this token is offside of context started at position (170:29). Try indenting this token further or using standard formatting conventions.  

Repro code

http://ratatosk.dynu.net/fantomas/#?code=AQ0GwUwF2MEsB2FgF4CwAoU3gA0CikAthAlABS7ABE8S1ANHgIJRQBOcARgK5QSUaCHkS4R2jYAGcAdKw7c+AqtSlhqAShkA1AIZgeEDQ0w4zZ3PM69+g6gAs4UKZIBuAD2OnzPlm2tKdlzsuggAxvaM3r4x5nAAZsBiYajAAAzAUPakNPH6UhDU0bElIBBgBTQchpoaQA&config=N4IgkgdgJgphAuBlADgQwMYwHIFcC2IAXAEwA0IACqgOYwDqAllPABZECcADORQE4wBnGLwBuMAKLQA8gDMAMgwgwiM1ABsh5RDDwN0AezX6IAQXiSoshUpXrNIFBhgAhGDP38Tvavjjwi8Lw4MFpomK7u-ADChsYBQSEOYTAmMvDCMXh4qPHBoU6p6bzaugZGELmJkLAIUhAAKrwAnoysthqJAEowHrC8UshwACIw6GqovKjwDHGEqh35mF76ONAjagy6RZVagXrwALL6sO1CAL5AA

nojaf commented 5 years ago

Not entirely sure this is still a problem. The following repro formats correctly I think: https://jindraivanek.gitlab.io/fantomas-ui/#?fantomas=preview-trivia&code=MQJwBARAygngzgFwKYFsB0ANFAbNAZASwDsBHCAWACgqB7ABySLFkVUx32JKquyQTAYwRAIYokYALyCAcmKRoA4v2HzeKgEZIAxlLABGdQLgAuQQFE+4ogOkZLqRgjQAFESDhIAFBAA8IgD5fAHpAiABKIzAANwAPPQAWHko+AWxiCS9wqSowCysnXLywLyEIdKIkCAAaQQBBBAQQAg0AV2RSyCJWlC0QGuK4NAamlvbvMrhsCLQANRFsVqRw2owR5raOsoALAgQ4AbiVouK1xo3xk+KSso0QESJtbZqr668CADMwLV1pAAYwAhtoxIB8Fp4KJRrtCkNhPJAmksIuFwkA&config=N4IgkgdgJgphAuBlADgQwMYwHIFcC2IAXAEwA0IACqgOYwDqAllPABZECcADAL5A

@SteveGilham can this be closed?