Elm-format: Elm-format should distinguish between different types of comments.

Created on 16 Jun 2017  路  2Comments  路  Source: avh4/elm-format

At the moment, if you have no imports, you cannot comment the top most function of your file. That comment will be pulled to the top of the file.

Example:

module Bla exposing (..)

-- I want to add a comment here
type alias Bla =
    { }

but elm format will make this

module Bla exposing (..)

-- I want to add a comment here


type alias Bla =
    { }

If it's a doc-comment, {-| -}, it makes sense to pull it to the top because it only makes sense to have doc comments above functions if you have a doc-comment in the module as well. But it doesn't make sense to be pulling -- and {- -} to the top of the file. We should be able to comment the top most function of our files even if we have no imports.

Most helpful comment

This is a case where elm-format is making the behavior of elm-make/elm-compiler more clear: If a module has no imports, you cannot have a doc comment on the first definition unless you also have a doc comment for the module before it--this is due to the behavior of elm-make and how it parses documentation. elm-format adjusts the spacing to make it more obvious how elm-make will interpret your doc comments.

All 2 comments

To elaborate, there seems to be a few more issues with the top comment. For example if I do have imports, then my first comment can be a doc-comment, but it can only be a doc-comment.

module Bla exposing (..)

import X


{-| Allowed
-}
type alias Bla =
    { }

But both of these will be reformatted:

module Bla exposing (..)

import X


-- This comment will be pushed up upon formatting
type alias Bla =
    { }
module Bla exposing (..)

import X


{- This comment will be pushed up upon formatting -}
type alias Bla =
    { }

This is a case where elm-format is making the behavior of elm-make/elm-compiler more clear: If a module has no imports, you cannot have a doc comment on the first definition unless you also have a doc comment for the module before it--this is due to the behavior of elm-make and how it parses documentation. elm-format adjusts the spacing to make it more obvious how elm-make will interpret your doc comments.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pdamoc picture pdamoc  路  8Comments

sporto picture sporto  路  7Comments

avh4 picture avh4  路  6Comments

rtfeldman picture rtfeldman  路  4Comments

ahstro picture ahstro  路  4Comments