lue-bird/elm-review-documentation-code-snippet/1.0.0

NOTE: the latest version is 1.1.3

Review.Documentation.CodeSnippet

Checks your small code examples in the readme, module headers and declaration comments for valid syntax, matching types and correctness by generating tests from these code snippets.

import Review.Documentation.CodeSnippet


config =
    [ Review.Documentation.CodeSnippet.check
    ]
check : Rule

Rule to generate tests from your documentation examples (readme, module header, declaration comment) and also to report syntax errors for these code snippets. There are two kinds of checks:

value checks

module Dict.Extra exposing (keySet)


{-| `Dict.keys` but returning a `Set` instead of a `List`.


    import Dict
    import Set


    type Letter
        = A
        | B
        | C


    Dict.fromList [ ( 0, A ), ( 1, B ), ( 2, C ) ]
        |> keySet
    --> Set.fromList [ 0, 1, 2 ]


    -- or
    Dict.fromList [ ( 0, A ), ( 1, B ), ( 2, C ) ]
        |> keySet
    -->
    Set.fromList
        [ 0
        , 1
        , 2
        ]


    -- or
    Dict.fromList [ ( 0, A ), ( 1, B ), ( 2, C ) ]
        |> keySet
    --> Set.fromList
    -->     [ 0
    -->     , 1
    -->     , 2
    -->     ]


-}
keySet = ...

This verifies that the actual value of the expression before --> is the same as the expected value after -->.

type checks

module Codec exposing (Codec, record, field, recordFinish, signedInt)


{-| Start creating a codec for a record.


    type alias Point =
        { x : Int, y : Int }


    Codec.record (\x y -> { x = x, y = y })
        |> Codec.field .x Codec.signedInt
        |> Codec.field .y Codec.signedInt
        |> Codec.recordFinish
    --: Codec Point
-}
record = ...

important The rule will only report syntax and type errors if your code snippet contains at least one of these two checks, so replace

{-| ...


    myResult : Cmd Int
    myResult =
        Ok 3 |> Cmd.Extra.fromResult


-}

with

{-| ...


    Ok 3 |> Cmd.Extra.fromResult
    --: Cmd Int


-}

Both checks will be run on all modules and the readme. If you want to disable this for e.g. generated or vendored code, use Review.Rule.ignoreErrorsForDirectories