Add NoDebug rules like they are in jfmengels/review-debug

This commit is contained in:
Jeroen Engels 2020-04-03 15:13:37 +02:00
parent a0df1118d9
commit 02d7665e91
5 changed files with 28 additions and 36 deletions

View File

@ -11,8 +11,8 @@ when inside the directory containing this file.
-}
import NoDebugLog
import NoDebugTodoOrToString
import NoDebug.Log
import NoDebug.TodoOrToString
import NoTodoComment
import NoUnused.CustomTypeConstructors2
import NoUnused.Variables
@ -24,8 +24,8 @@ import Review.Rule as Rule exposing (Rule)
config : List Rule
config =
[ NoDebugLog.rule
, NoDebugTodoOrToString.rule
[ NoDebug.Log.rule
, NoDebug.TodoOrToString.rule
|> Rule.ignoreErrorsForDirectories [ "tests/" ]
, NoUnused.CustomTypeConstructors2.rule
, NoUnused.Variables.rule

View File

@ -1,6 +1,6 @@
module NoDebugLog exposing (rule)
module NoDebug.Log exposing (rule)
{-| Forbid the use of [`Debug.log`](https://package.elm-lang.org/packages/elm/core/latest/Debug#log) before it goes into production or fails in the CI.
{-| Forbid the use of [`Debug.log`](https://package.elm-lang.org/packages/elm/core/latest/Debug#log).
# Rule
@ -18,8 +18,10 @@ import Review.Rule as Rule exposing (Error, Rule)
{-| Forbid the use of [`Debug.log`](https://package.elm-lang.org/packages/elm/core/latest/Debug) before it goes into production or fails in the CI.
`Debug.log` is useful to debug your code, but should not be pushed to production.
config =
[ NoDebugLog.rule
[ NoDebug.Log.rule
]

View File

@ -1,6 +1,6 @@
module NoDebugLogTest exposing (all)
module NoDebug.LogTest exposing (all)
import NoDebugLog exposing (rule)
import NoDebug.Log exposing (rule)
import Review.Test exposing (ReviewResult)
import Test exposing (Test, describe, test)

View File

@ -1,4 +1,4 @@
module NoDebugTodoOrToString exposing (rule)
module NoDebug.TodoOrToString exposing (rule)
{-|
@ -16,15 +16,15 @@ import Elm.Syntax.Node as Node exposing (Node)
import Review.Rule as Rule exposing (Error, Rule)
{-| Forbid the use of [`Debug.todo`] and [`Debug.toString`] before it goes into
production or fails in the CI.
{-| Forbid the use of [`Debug.todo`] and [`Debug.toString`].
config =
[ NoDebugTodoOrToString.rule
[ NoDebug.TodoOrToString.rule
]
The reason why they are separate handled in a different rule than [`Debug.log`]
is because they are reasonable and useful to have in tests.
The reason why there is a is separate rule for handling [`Debug.log`] and one for
handling [`Debug.todo`] and [`Debug.toString`], is because these two functions
are reasonable and useful to have in tests.
You can for instance create test data without having to handle the error case
everywhere. If you do enter the error case in the following example, then tests
@ -42,8 +42,10 @@ will fail.
If you want to allow these functions in tests but not in production code, you
can configure the rule like this.
import Review.Rule as Rule exposing (Rule)
config =
[ NoDebugTodoOrToString.rule
[ NoDebug.TodoOrToString.rule
|> Rule.ignoreErrorsForDirectories [ "tests/" ]
]
@ -69,18 +71,6 @@ can configure the rule like this.
else
b
# When (not) to use this rule
You should use this rule if you're developing a package meant to be published,
or an application that is put into production, and wish to know about the use of
[`Debug.log`](https://package.elm-lang.org/packages/elm/core/latest/Debug#log)
module before committing your changes.
You should not use this rule if you are developing an application that is not
put into production, and you do not care about having stray debug logs, and you
do not ship to production.
[`Debug.log`]: https://package.elm-lang.org/packages/elm/core/latest/Debug#log
[`Debug.todo`]: https://package.elm-lang.org/packages/elm/core/latest/Debug#todo
[`Debug.toString`]: https://package.elm-lang.org/packages/elm/core/latest/Debug#toString
@ -88,7 +78,7 @@ do not ship to production.
-}
rule : Rule
rule =
Rule.newModuleRuleSchema "NoDebugTodoOrToString" init
Rule.newModuleRuleSchema "NoDebug.TodoOrToString" init
|> Rule.withImportVisitor importVisitor
|> Rule.withExpressionVisitor expressionVisitor
|> Rule.fromModuleRuleSchema

View File

@ -1,10 +1,15 @@
module NoDebugTodoOrToStringTest exposing (all)
module NoDebug.TodoOrToStringTest exposing (all)
import NoDebugTodoOrToString exposing (rule)
import NoDebug.TodoOrToString exposing (rule)
import Review.Test exposing (ReviewResult)
import Test exposing (Test, describe, test)
all : Test
all =
describe "NoDebug.TodoOrToString" tests
testRule : String -> ReviewResult
testRule string =
"module A exposing (..)\n\n"
@ -156,8 +161,3 @@ a = toString "" 1
"""
|> Review.Test.expectNoErrors
]
all : Test
all =
describe "NoDebugTodoOrToString" tests