J. *_*ers 0 code-formatting elm
所以我今天开始学习榆木。我使用VSCode作为编辑器。
我按照文档进行了设置和安装elm,也el-format通过npm install -g elm elm-format。我还安装了VSCode Elm扩展。
接下来,在我的settings.json设定中:
"[elm]": {
"editor.formatOnSave": true
},
Run Code Online (Sandbox Code Playgroud)
然后我继续本教程。其中的代码格式如下:
import Browser
import Html exposing (Html, Attribute, div, input, text)
import Html.Attributes exposing (..)
import Html.Events exposing (onInput)
-- MAIN
main =
Browser.sandbox { init = init, update = update, view = view }
-- MODEL
type alias Model =
{ content : String
}
init : Model
init =
{ content = "" }
-- UPDATE
type Msg
= Change String
update : Msg -> Model -> Model
update msg model =
case msg of
Change newContent ->
{ model | content = newContent }
-- VIEW
view : Model -> Html Msg
view model =
div []
[ input [ placeholder "Text to reverse", value model.content, onInput Change ] []
, div [] [ text (String.reverse model.content) ]
]
Run Code Online (Sandbox Code Playgroud)
但是当我碰到保险柜时,它会像这样格式化代码:
module Main exposing (Model, Msg(..), init, main, update, view)
import Browser
import Html exposing (Attribute, Html, div, input, text)
import Html.Attributes exposing (..)
import Html.Events exposing (onInput)
-- MAIN
main =
Browser.sandbox { init = init, update = update, view = view }
-- MODEL
type alias Model =
{ content : String
}
init : Model
init =
{ content = "" }
-- UPDATE
type Msg
= Change String
update : Msg -> Model -> Model
update msg model =
case msg of
Change newContent ->
{ model | content = newContent }
-- VIEW
view : Model -> Html Msg
view model =
div []
[ input [ placeholder "Text to reverse", value model.content, onInput Change ] []
, div [] [ text (String.reverse model.content) ]
]
Run Code Online (Sandbox Code Playgroud)
因此,它增加了额外的行,并增加了额外module Main exposing ...的空间。我尝试使用VSCode中的页脚再次将空格设置为2,但这无济于事。
我的问题是:
module Main ...吗?首先,这个问题太宽泛,主要是基于观点的,因此可能会被封闭。我认为它更适合于论坛。
就是说,无论如何,我将尽力回答最好的问题,因为它在这里:
是?如果不公开某些内容,大多数模块将不会非常有用,并且最好明确指出要公开的内容。
elm-format 是社区标准,所以是4。
你不能 这是设计使然。在各个论坛上也对此进行了讨论。这是一个讨论它的问题
您必须向Evan询问。这可能与网络格式化有关,或者只是Evan懒惰。
| 归档时间: |
|
| 查看次数: |
71 次 |
| 最近记录: |