avh4 / elm-format

elm-format formats Elm source code according to a standard set of rules based on the official Elm Style Guide
BSD 3-Clause "New" or "Revised" License
1.31k stars 148 forks source link

Avoid changing definition docs into module docs #771

Open avh4 opened 2 years ago

avh4 commented 2 years ago

Example input:

module Foo exposing (..)

{-| returns 5 -}
foo = 5

Current output:

module Foo exposing (..)

{-| returns 5 -}

foo = 5

The reason this was done is because elm make will use the comment as a module documentation. But this is annoying to people who just want the comment to stay with the definition. I hear confusion about this every year or two.

Proposal: A better solution would be to insert an empty module doc, so output would be:

module Foo exposing (..)

{-| -}

{-| returns 5 -}
foo = 5

The trigger for this should probably be whether or not the doc comment is on the line immediately above the definition. The comment should be read as the module docs if there is more space between them.

lydell commented 2 years ago

That might lead to people reporting a “bug” where an extra {-| -} appears out of the blue. So maybe we have to do this:

module Foo exposing (..)

{-| Module documentation comment inserted by elm-format to avoid an `elm make` bug – see https://somewhere -}

{-| returns 5 -}
foo = 5