rule : Check -> Review.Rule.Rule
Forbid unsafe types in ports.
config : List Rule
config =
[ NoUnsafePorts.rule NoUnsafePorts.any
]
This rule reports any ports that do not send/receive a Json.Encode.Value
.
If a port expecting an Int
receives a Float
it will cause a runtime error. We can prevent this by just wrapping the incoming data as Json.Encode.Value
and handling the data through a Decoder
instead. This guarantees that your application provides some sort of error handling. This is discussed in the Elm guide under Verifying Flags.
port action : (Json.Decode.Value -> msg) -> Sub msg
port alarm : Json.Encode.Value -> Cmd msg
port action : (Int -> msg) -> Sub msg
port alarm : String -> Cmd msg
Value
from Json.Encode
or Json.Decode
and result in a Cmd
.Value
from Json.Encode
or Json.Decode
and result in a Sub
.Cmd
, Sub
and Value
only - do not alias these types.You can try this rule out by running the following command:
elm-review --template sparksp/elm-review-ports/example --rules NoUnsafePorts
any : Check
Check both incoming and outgoing ports.
config : List Rule
config =
[ NoUnsafePorts.rule NoUnsafePorts.any
]
This is the option you will want most of the time.
onlyIncomingPorts : Check
Check incoming ports only.
config : List Rule
config =
[ NoUnsafePorts.rule NoUnsafePorts.onlyIncomingPorts
]
Use this option if you want to allow basic types in outgoing ports.
Check type.