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

KeepIndentInBranch not respected when returning short function application #1779

Closed
3 tasks
nojaf opened this issue Jun 15, 2021 · 3 comments · Fixed by #1784
Closed
3 tasks

KeepIndentInBranch not respected when returning short function application #1779

nojaf opened this issue Jun 15, 2021 · 3 comments · Fixed by #1784

Comments

@nojaf
Copy link
Contributor

nojaf commented Jun 15, 2021

Issue created from fantomas-online

Code

let private parseModel (modelSrc: string) : Result<MyReturnType, string list> =
  if not (File.Exists(modelSrc)) then
    Error [ sprintf "Provided modelSrc \"%s\" does not exist" modelSrc ]
  else
    let graph = new QueryableGraph()
    graph.LoadFromFile(modelSrc, TurtleParser())

    let xsdPath =
      Path.Combine(Directory.GetCurrentDirectory(), "Some.xsd")

    let ontologyPath =
      Path.Combine(Directory.GetCurrentDirectory(), "Some.ttl")

    let ontoGraph = new OntologyGraph()
    FileLoader.Load(ontoGraph, ontologyPath)

    let validationErrors =
      GraphValidation.validate xsdPath ontoGraph "http://company.com/meh" graph

    if List.isEmpty validationErrors then
      Ok graph
    else
      Error validationErrors

Result

let private parseModel (modelSrc: string) : Result<MyReturnType, string list> =
    if not (File.Exists(modelSrc)) then
        Error [ sprintf "Provided modelSrc \"%s\" does not exist" modelSrc ]
    else
        let graph = new QueryableGraph()
        graph.LoadFromFile(modelSrc, TurtleParser())

        let xsdPath =
            Path.Combine(Directory.GetCurrentDirectory(), "Some.xsd")

        let ontologyPath =
            Path.Combine(Directory.GetCurrentDirectory(), "Some.ttl")

        let ontoGraph = new OntologyGraph()
        FileLoader.Load(ontoGraph, ontologyPath)

        let validationErrors =
            GraphValidation.validate xsdPath ontoGraph "http://company.com/meh" graph

        if List.isEmpty validationErrors then
            Ok graph
        else
            Error validationErrors

Problem description

This is a good example where AST alone is probably not sufficient enough to make the right call whether this should keep the indent.
@Smaug123 I'm correct that is should not indent the else branch right?

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 06/12/2021 10:31:17 - 8f71594

    { config with
                KeepIndentInBranch = true }

Did you know that you can ignore files when formatting from fantomas-tool or the FAKE targets by using a .fantomasignore file?

@Smaug123
Copy link
Contributor

I agree, this should probably unindent. What's the problem that means the AST doesn't determine what to do here?

@nojaf
Copy link
Contributor Author

nojaf commented Jun 16, 2021

Oh I mean when you have something like this:

Error [ sprintf "Provided modelSrc \"%s\" does not exist" modelSrc ]

the matching AST looks like

App
                (NonAtomic, false, Ident Error,
                 ArrayOrListOfSeqExpr
                   (false,
                    CompExpr
                      (true, { contents = true },
                       App
                         (NonAtomic, false,
                          App
                            (NonAtomic, false, Ident sprintf,
                             Const
                               (String
                                  ("Provided modelSrc "%s" does not exist",
                                   tmp.fsx (2,20--2,61) IsSynthetic=false),
                                tmp.fsx (2,20--2,61) IsSynthetic=false),
                             tmp.fsx (2,12--2,61) IsSynthetic=false),
                          Ident modelSrc, tmp.fsx (2,12--2,70) IsSynthetic=false),
                       tmp.fsx (2,12--2,70) IsSynthetic=false),
                    tmp.fsx (2,10--2,72) IsSynthetic=false),
                 tmp.fsx (2,4--2,72) IsSynthetic=false)

so a nested SynExpr.App shape and this is difficult to recognize as a short statement.
In this case, it is a oneliner, but it could also be longer like

Error 
    [ 
        sprintf "Provided modelSrc \"%s\" does not exist" modelSrc
        // some comment, same AST though
    ]

I'm guessing you would indent if the application was multiline.
Or not?

@nojaf
Copy link
Contributor Author

nojaf commented Jun 23, 2021

I'm going to solve this purely based on AST.
I do think it makes sense as you are immediately returning a functional call as an expression.
So that does kinda counts as an early return to me.
We can discuss this further when new evidence pops up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants