elm-review/src/Lint/Rules/NoDebug.elm

68 lines
1.2 KiB
Elm
Raw Normal View History

2017-01-29 22:03:31 +03:00
module Lint.Rules.NoDebug exposing (rule)
2017-01-07 23:17:01 +03:00
{-|
@docs rule
# Fail
if Debug.log "condition" condition then a else b
if condition then
Debug.crash "Nooo!"
else
value
# Success
if condition then
a
else
b
-}
2017-01-07 23:17:01 +03:00
import Ast.Expression exposing (..)
2017-01-29 22:03:31 +03:00
import Lint exposing (lint, doNothing)
import Lint.Types exposing (LintRule, Error, Direction(..))
2017-01-07 23:17:01 +03:00
type alias Context =
{}
{-| Forbid the use of `Debug` before it goes into production.
rules =
[ NoDebug.rule
]
-}
rule : String -> List Error
rule input =
lint input implementation
implementation : LintRule Context
implementation =
2017-01-07 23:17:01 +03:00
{ statementFn = doNothing
, typeFn = doNothing
, expressionFn = expressionFn
2017-01-08 18:24:59 +03:00
, moduleEndFn = (\ctx -> ( [], ctx ))
, initialContext = Context
2017-01-07 23:17:01 +03:00
}
2017-01-18 01:32:30 +03:00
error : Error
error =
Error "NoDebug" "Forbidden use of Debug"
expressionFn : Context -> Direction Expression -> ( List Error, Context )
2017-01-07 23:17:01 +03:00
expressionFn ctx node =
case node of
Enter (Variable vars) ->
2017-01-07 23:17:01 +03:00
if List.member "Debug" vars then
2017-01-18 01:32:30 +03:00
( [ error ], ctx )
2017-01-07 23:17:01 +03:00
else
( [], ctx )
_ ->
( [], ctx )