2018-11-11 01:43:58 +03:00
|
|
|
module Lint.Rule.NoDebug exposing (rule)
|
2017-01-07 23:17:01 +03:00
|
|
|
|
2017-01-30 00:31:51 +03:00
|
|
|
{-|
|
2018-11-05 16:44:22 +03:00
|
|
|
|
2017-01-30 00:31:51 +03:00
|
|
|
@docs rule
|
|
|
|
|
2018-11-05 16:44:22 +03:00
|
|
|
|
2017-01-30 00:31:51 +03:00
|
|
|
# Fail
|
|
|
|
|
2018-11-05 16:44:22 +03:00
|
|
|
if Debug.log "condition" condition then
|
|
|
|
a
|
|
|
|
|
|
|
|
else
|
|
|
|
b
|
|
|
|
|
2017-01-30 00:31:51 +03:00
|
|
|
if condition then
|
|
|
|
Debug.crash "Nooo!"
|
2018-11-05 16:44:22 +03:00
|
|
|
|
2017-01-30 00:31:51 +03:00
|
|
|
else
|
|
|
|
value
|
|
|
|
|
2018-11-05 16:44:22 +03:00
|
|
|
|
2017-01-30 00:31:51 +03:00
|
|
|
# Success
|
|
|
|
|
|
|
|
if condition then
|
|
|
|
a
|
2018-11-05 16:44:22 +03:00
|
|
|
|
2017-01-30 00:31:51 +03:00
|
|
|
else
|
|
|
|
b
|
2018-11-05 16:44:22 +03:00
|
|
|
|
2017-01-30 00:31:51 +03:00
|
|
|
-}
|
|
|
|
|
2018-11-05 21:00:17 +03:00
|
|
|
import Elm.Syntax.Expression exposing (Expression(..))
|
2018-11-06 15:15:23 +03:00
|
|
|
import Elm.Syntax.Node exposing (Node, range, value)
|
2018-11-11 01:37:18 +03:00
|
|
|
import Lint exposing (Rule, lint)
|
|
|
|
import Lint.Error exposing (Error)
|
2019-06-15 15:47:10 +03:00
|
|
|
import Lint.Rule as Rule
|
2017-01-07 23:17:01 +03:00
|
|
|
|
|
|
|
|
|
|
|
type alias Context =
|
2019-06-15 15:47:10 +03:00
|
|
|
()
|
2017-01-07 23:17:01 +03:00
|
|
|
|
|
|
|
|
2017-01-30 00:31:51 +03:00
|
|
|
{-| Forbid the use of `Debug` before it goes into production.
|
|
|
|
|
|
|
|
rules =
|
|
|
|
[ NoDebug.rule
|
|
|
|
]
|
2018-11-05 16:44:22 +03:00
|
|
|
|
2017-01-30 00:31:51 +03:00
|
|
|
-}
|
2018-11-11 01:37:18 +03:00
|
|
|
rule : Rule
|
2019-06-15 22:14:40 +03:00
|
|
|
rule =
|
|
|
|
lint implementation
|
2017-01-16 01:24:37 +03:00
|
|
|
|
|
|
|
|
2019-06-15 15:47:10 +03:00
|
|
|
implementation : Rule.Implementation Context
|
2017-01-16 01:24:37 +03:00
|
|
|
implementation =
|
2019-06-15 15:47:10 +03:00
|
|
|
Rule.create ()
|
2019-06-15 21:32:41 +03:00
|
|
|
|> Rule.withExpressionVisitor expressionVisitor
|
2017-01-07 23:17:01 +03:00
|
|
|
|
|
|
|
|
2018-11-11 01:37:18 +03:00
|
|
|
error : Node a -> Error
|
2018-11-06 15:15:23 +03:00
|
|
|
error node =
|
2018-11-11 01:37:18 +03:00
|
|
|
Error "NoDebug" "Forbidden use of Debug" (range node)
|
2017-01-16 01:30:33 +03:00
|
|
|
|
|
|
|
|
2019-06-15 21:32:41 +03:00
|
|
|
expressionVisitor : Context -> Rule.Direction -> Node Expression -> ( List Error, Context )
|
|
|
|
expressionVisitor ctx direction node =
|
2018-11-05 21:55:03 +03:00
|
|
|
case ( direction, value node ) of
|
2019-06-15 15:47:10 +03:00
|
|
|
( Rule.Enter, FunctionOrValue moduleName fnName ) ->
|
2018-11-05 21:55:03 +03:00
|
|
|
if List.member "Debug" moduleName then
|
2018-11-06 15:15:23 +03:00
|
|
|
( [ error node ], ctx )
|
2018-11-05 16:44:22 +03:00
|
|
|
|
2018-11-05 21:55:03 +03:00
|
|
|
else
|
|
|
|
( [], ctx )
|
2017-01-07 23:17:01 +03:00
|
|
|
|
|
|
|
_ ->
|
|
|
|
( [], ctx )
|