elm-review/tests/NoDebug/TodoOrToStringTest.elm

160 lines
5.5 KiB
Elm
Raw Normal View History

module NoDebug.TodoOrToStringTest exposing (all)
2020-03-07 01:45:39 +03:00
import NoDebug.TodoOrToString exposing (rule)
2020-08-09 19:55:15 +03:00
import Review.Test exposing (ReviewResult)
2020-03-07 01:45:39 +03:00
import Test exposing (Test, describe, test)
2020-08-09 19:55:15 +03:00
testRule : String -> ReviewResult
testRule string =
"module A exposing (..)\n\n"
++ string
|> Review.Test.run rule
2020-03-07 01:45:39 +03:00
todoMessage : String
todoMessage =
"Remove the use of `Debug.todo` before shipping to production"
todoDetails : List String
todoDetails =
[ "`Debug.todo` can be useful when developing, but is not meant to be shipped to production or published in a package. I suggest removing its use before committing and attempting to push to production."
]
toStringMessage : String
toStringMessage =
"Remove the use of `Debug.toString` before shipping to production"
toStringDetails : List String
toStringDetails =
[ "`Debug.toString` can be useful when developing, but is not meant to be shipped to production or published in a package. I suggest removing its use before committing and attempting to push to production."
]
2020-08-09 19:55:15 +03:00
all : Test
all =
describe "NoDebug.TodoOrToString"
[ test "should not report normal function calls" <|
\() ->
testRule """
2020-03-07 01:45:39 +03:00
a = foo n
b = bar.foo n
c = debug
c = toString
c = List.toString
d = debug.todo n
e = debug.toString n
"""
2020-08-09 19:55:15 +03:00
|> Review.Test.expectNoErrors
, test "should not report Debug.log calls" <|
\() ->
testRule """
2020-03-07 01:45:39 +03:00
a = Debug.log n
"""
2020-08-09 19:55:15 +03:00
|> Review.Test.expectNoErrors
, test "should report Debug.todo use" <|
\() ->
testRule "a = Debug.todo"
|> Review.Test.expectErrors
[ Review.Test.error
{ message = todoMessage
, details = todoDetails
, under = "Debug.todo"
}
]
, test "should report Debug.toString use" <|
\() ->
testRule "a = Debug.toString"
|> Review.Test.expectErrors
[ Review.Test.error
{ message = toStringMessage
, details = toStringDetails
, under = "Debug.toString"
}
]
, test "should not report calls from a module containing Debug but that is not Debug" <|
\() ->
testRule """
2020-03-07 01:45:39 +03:00
a = Foo.Debug.todo 1
b = Debug.Foo.todo 1
a = Foo.Debug.toString 1
b = Debug.Foo.toString 1
2020-08-09 19:55:15 +03:00
"""
|> Review.Test.expectNoErrors
, test "should not report the import of the Debug module" <|
\() ->
testRule "import Debug"
|> Review.Test.expectNoErrors
, test "should report the use of `todo` when `todo` has been explicitly imported" <|
\() ->
testRule """
2020-03-07 01:45:39 +03:00
import Debug exposing (todo)
a = todo ""
"""
2020-08-09 19:55:15 +03:00
|> Review.Test.expectErrors
[ Review.Test.error
{ message = todoMessage
, details = todoDetails
, under = "todo"
}
|> Review.Test.atExactly { start = { row = 5, column = 5 }, end = { row = 5, column = 9 } }
]
, test "should report the use of `todo` when `todo` has been implicitly imported" <|
\() ->
testRule """
2020-03-07 01:45:39 +03:00
import Debug exposing (..)
a = todo "" 1
"""
2020-08-09 19:55:15 +03:00
|> Review.Test.expectErrors
[ Review.Test.error
{ message = todoMessage
, details = todoDetails
, under = "todo"
}
]
, test "should not report the use of `todo` when it has not been imported" <|
\() ->
testRule """
2020-03-07 01:45:39 +03:00
import Debug exposing (log)
a = todo "" 1
"""
2020-08-09 19:55:15 +03:00
|> Review.Test.expectNoErrors
, test "should report the use of `toString` when `toString` has been explicitly imported" <|
\() ->
testRule """
2020-03-07 01:45:39 +03:00
import Debug exposing (toString)
a = toString ""
"""
2020-08-09 19:55:15 +03:00
|> Review.Test.expectErrors
[ Review.Test.error
{ message = toStringMessage
, details = toStringDetails
, under = "toString"
}
|> Review.Test.atExactly { start = { row = 5, column = 5 }, end = { row = 5, column = 13 } }
]
, test "should report the use of `toString` when `toString` has been implicitly imported" <|
\() ->
testRule """
2020-03-07 01:45:39 +03:00
import Debug exposing (..)
a = toString "" 1
"""
2020-08-09 19:55:15 +03:00
|> Review.Test.expectErrors
[ Review.Test.error
{ message = toStringMessage
, details = toStringDetails
, under = "toString"
}
]
, test "should not report the use of `toString` when it has not been imported" <|
\() ->
testRule """
2020-03-07 01:45:39 +03:00
import Debug exposing (log)
a = toString "" 1
"""
2020-08-09 19:55:15 +03:00
|> Review.Test.expectNoErrors
]