fsprojects / fantomas

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

Fantomas removes module and namespace if it is only 1 word (without dots) #380

Closed zakaluka closed 5 years ago

zakaluka commented 5 years ago

Description

Fantomas removes the module and namespace lines if they are the first line in the file AND they don't contain any dots.

However, if the module or namespace contains dots (e.g. Shared.Utility), the line is not removed.

This happens when using formatCode in a FAKE build.fsx file.

Options:

// Common Fantomas Config to reformat files and check that formatting complies
let fantomasConfig =
    { FormatConfig.Default with
        StrictMode = true
        IndentSpaceNum = 2
        SpaceBeforeColon = false
    }

Repro code

Incorrect

Input:

namespace Shared

type Counter = int

Output:

type Counter = int

Expected:

namespace Shared

type Counter = int

But this works okay

Input:

module ZenCase.Shared.Utility

/// Allows debugging output without breaking function chains
let tee f x = f x |> ignore; x

Output:

module ZenCase.Shared.Utility

/// Allows debugging output without breaking function chains
let tee f x =
  f x |> ignore
  x

http://ratatosk.dynu.net/fantomas/#?code=HYQwtgpgzgDiDGEAEBlAFiAThAJgWAChCAXATxmQGEB7AV2GIkyQF4kBLBwwoA&config=N4IgkgdgJgphAuBlADgQwMYwHIFcC2IAXACwA0IACqgOYwDqAllPABZEAcADORQE4wBnGLwBuMAKLQA8gDMAMgwgwiM1ABsh5RDDwN0AezX6IAQXiSoshUpXrNIFBhgAhGDP38Tvavjjwi8Lw4MFpomK7u-ADChsYBQSEOYTAmMvDCMXh4qPHBoU6p6bzaugZGELmJkLAIUhAAKrwAnoysthqJAEowHrC8UshwACIw6GqovKjwDHGEqh35mF76ONAjagy6RZVagXrwALL6sO1CAL5AA

NOTE: This work correctly online, but not when part of the FAKE pipeline.

EDIT: Matched config with the options from build.fsx. Despite that, it will works correctly online. http://ratatosk.dynu.net/fantomas/#?code=HYQwtgpgzgDiDGEAEBlAFiAThAJgWAChCAXATxmQGEB7AV2GIkyQF4kBLBwwoA&config=N4IgkgdgJgphAuBlADgQwMYwHIFcC2IAXAEwA0IACqgOYwDqAllPABZEAcADORQE4wBnGLwBuMAKLQA8gDMAMgwgwiM1ABsh5RDDwN0AezX6IAQXiSoshUpXrNIFBhgAhGDP38Tvavjjwi8Lw4MFpomK7u-ADChsa2GiEOYTAmMvDCMXh4qAFBiY6Yqem82roGRhC5weSQsAhSEAAqvACejKzx9gBKMB6wvFLIcAAiMOhqqLyo8AxxhKoJoU5e+jjQo2oMusVV+YF68ACy+rC7AL5AA

nojaf commented 5 years ago

Hi, I did an attempt to reproduce this in https://github.com/fsprojects/fantomas/pull/434/commits/097bbcaab733bef8e147c4caf4f4072d338c0fcb. I don't think this is an issue anymore. What version of fantomas are you here?

nojaf commented 5 years ago

Please reopen if the problem still occurs with the latest beta.