2017-01-29 22:03:31 +03:00
|
|
|
module Lint.Rules.NoDebug exposing (rule)
|
2017-01-07 23:17:01 +03:00
|
|
|
|
2017-01-30 00:31:51 +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 =
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
2017-01-30 00:31:51 +03:00
|
|
|
{-| Forbid the use of `Debug` before it goes into production.
|
|
|
|
|
|
|
|
rules =
|
|
|
|
[ NoDebug.rule
|
|
|
|
]
|
|
|
|
-}
|
2017-01-16 01:24:37 +03:00
|
|
|
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 ))
|
2017-01-16 01:24:37 +03:00
|
|
|
, 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"
|
2017-01-16 01:30:33 +03:00
|
|
|
|
|
|
|
|
2017-01-08 17:31:17 +03:00
|
|
|
expressionFn : Context -> Direction Expression -> ( List Error, Context )
|
2017-01-07 23:17:01 +03:00
|
|
|
expressionFn ctx node =
|
|
|
|
case node of
|
2017-01-08 17:31:17 +03:00
|
|
|
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 )
|