Add details in tests

This commit is contained in:
Jeroen Engels 2019-07-28 00:16:57 +02:00
parent 68b3b72f8d
commit e27ea65b1a
6 changed files with 93 additions and 1 deletions

View File

@ -108,6 +108,7 @@ type alias CodeInspector =
type ExpectedError
= ExpectedError
{ message : String
, details : List String
, under : Under
}
@ -263,10 +264,11 @@ fail unless you use [`atExactly`](#atExactly) to remove any ambiguity of where t
error should be used.
-}
error : { message : String, under : String } -> ExpectedError
error : { message : String, details : List String, under : String } -> ExpectedError
error input =
ExpectedError
{ message = input.message
, details = input.details
, under = Under input.under
}

View File

@ -17,6 +17,12 @@ message =
"Remove the use of `Debug` before shipping to production"
details : List String
details =
[ "The `Debug` module is useful when developing, but is not meant to be shipped to production or published in a package. I suggest removing it's use before committing and attempting to push to production."
]
tests : List Test
tests =
[ test "should not report normal function calls" <|
@ -35,6 +41,7 @@ d = debug.log n
|> Lint.Test.expectErrors
[ Lint.Test.error
{ message = message
, details = details
, under = "Debug.log"
}
]
@ -44,6 +51,7 @@ d = debug.log n
|> Lint.Test.expectErrors
[ Lint.Test.error
{ message = message
, details = details
, under = "Debug.log"
}
]
@ -56,11 +64,13 @@ b = Debug.log z
|> Lint.Test.expectErrors
[ Lint.Test.error
{ message = message
, details = details
, under = "Debug.log"
}
|> Lint.Test.atExactly { start = { row = 4, column = 5 }, end = { row = 4, column = 14 } }
, Lint.Test.error
{ message = message
, details = details
, under = "Debug.log"
}
|> Lint.Test.atExactly { start = { row = 5, column = 5 }, end = { row = 5, column = 14 } }
@ -71,6 +81,7 @@ b = Debug.log z
|> Lint.Test.expectErrors
[ Lint.Test.error
{ message = message
, details = details
, under = "Debug.todo"
}
]
@ -80,6 +91,7 @@ b = Debug.log z
|> Lint.Test.expectErrors
[ Lint.Test.error
{ message = message
, details = details
, under = "Debug.foo"
}
]
@ -89,6 +101,7 @@ b = Debug.log z
|> Lint.Test.expectErrors
[ Lint.Test.error
{ message = message
, details = details
, under = "Debug.log"
}
]
@ -98,6 +111,7 @@ b = Debug.log z
|> Lint.Test.expectErrors
[ Lint.Test.error
{ message = message
, details = details
, under = "Debug.log"
}
]
@ -107,6 +121,7 @@ b = Debug.log z
|> Lint.Test.expectErrors
[ Lint.Test.error
{ message = message
, details = details
, under = "Debug.log"
}
]
@ -116,6 +131,7 @@ b = Debug.log z
|> Lint.Test.expectErrors
[ Lint.Test.error
{ message = message
, details = details
, under = "Debug.log"
}
]
@ -125,6 +141,7 @@ b = Debug.log z
|> Lint.Test.expectErrors
[ Lint.Test.error
{ message = message
, details = details
, under = "Debug.log"
}
]
@ -134,6 +151,7 @@ b = Debug.log z
|> Lint.Test.expectErrors
[ Lint.Test.error
{ message = message
, details = details
, under = "Debug.log"
}
]
@ -143,6 +161,7 @@ b = Debug.log z
|> Lint.Test.expectErrors
[ Lint.Test.error
{ message = message
, details = details
, under = "Debug.log"
}
]
@ -152,6 +171,7 @@ b = Debug.log z
|> Lint.Test.expectErrors
[ Lint.Test.error
{ message = message
, details = details
, under = "Debug.log"
}
]
@ -161,6 +181,7 @@ b = Debug.log z
|> Lint.Test.expectErrors
[ Lint.Test.error
{ message = message
, details = details
, under = "Debug.log"
}
]
@ -170,6 +191,7 @@ b = Debug.log z
|> Lint.Test.expectErrors
[ Lint.Test.error
{ message = message
, details = details
, under = "Debug.log"
}
]
@ -182,6 +204,7 @@ a = case Debug.log a b of
|> Lint.Test.expectErrors
[ Lint.Test.error
{ message = message
, details = details
, under = "Debug.log"
}
]
@ -194,6 +217,7 @@ a = case a of
|> Lint.Test.expectErrors
[ Lint.Test.error
{ message = message
, details = details
, under = "Debug.log"
}
]
@ -206,6 +230,7 @@ a = let b = Debug.log a b
|> Lint.Test.expectErrors
[ Lint.Test.error
{ message = message
, details = details
, under = "Debug.log"
}
]
@ -218,6 +243,7 @@ a = let b = c
|> Lint.Test.expectErrors
[ Lint.Test.error
{ message = message
, details = details
, under = "Debug.log"
}
]
@ -234,6 +260,7 @@ b = Debug.Foo.log 1
|> Lint.Test.expectErrors
[ Lint.Test.error
{ message = message
, details = details
, under = "Debug"
}
]
@ -243,6 +270,7 @@ b = Debug.Foo.log 1
|> Lint.Test.expectErrors
[ Lint.Test.error
{ message = message
, details = details
, under = "Debug"
}
]

View File

@ -37,6 +37,7 @@ d = if n >= 1 then 1 else 2
|> Lint.Test.expectErrors
[ Lint.Test.error
{ message = "Unnecessary comparison with `True`"
, details = [ "You can simplify this expression by removing the `==` operator and the value `True`." ]
, under = "b == True"
}
]
@ -46,6 +47,7 @@ d = if n >= 1 then 1 else 2
|> Lint.Test.expectErrors
[ Lint.Test.error
{ message = "Unnecessary comparison with `True`"
, details = [ "You can simplify this expression by removing the `==` operator and the value `True`." ]
, under = "True == b"
}
]
@ -55,6 +57,7 @@ d = if n >= 1 then 1 else 2
|> Lint.Test.expectErrors
[ Lint.Test.error
{ message = "Unnecessary comparison with `False`"
, details = [ "You can simplify this expression by removing the `==` operator and the value `False`." ]
, under = "b == False"
}
]
@ -64,6 +67,7 @@ d = if n >= 1 then 1 else 2
|> Lint.Test.expectErrors
[ Lint.Test.error
{ message = "Unnecessary comparison with `False`"
, details = [ "You can simplify this expression by removing the `==` operator and the value `False`." ]
, under = "False == b"
}
]
@ -73,6 +77,7 @@ d = if n >= 1 then 1 else 2
|> Lint.Test.expectErrors
[ Lint.Test.error
{ message = "Unnecessary comparison with `True`"
, details = [ "You can simplify this expression by removing the `/=` operator and the value `True`." ]
, under = "b /= True"
}
]
@ -82,6 +87,7 @@ d = if n >= 1 then 1 else 2
|> Lint.Test.expectErrors
[ Lint.Test.error
{ message = "Unnecessary comparison with `True`"
, details = [ "You can simplify this expression by removing the `/=` operator and the value `True`." ]
, under = "True /= b"
}
]
@ -91,6 +97,7 @@ d = if n >= 1 then 1 else 2
|> Lint.Test.expectErrors
[ Lint.Test.error
{ message = "Unnecessary comparison with `False`"
, details = [ "You can simplify this expression by removing the `/=` operator and the value `False`." ]
, under = "b /= False"
}
]
@ -100,6 +107,7 @@ d = if n >= 1 then 1 else 2
|> Lint.Test.expectErrors
[ Lint.Test.error
{ message = "Unnecessary comparison with `False`"
, details = [ "You can simplify this expression by removing the `/=` operator and the value `False`." ]
, under = "False /= b"
}
]

View File

@ -10,6 +10,13 @@ testRule options =
Lint.Test.run (rule options)
details : List String
details =
[ "Exposing `(..)` from a module means making all it's exposed functions and types available in the file's namespace. This makes it hard to tell which module a function or type comes from."
, "A preferred pattern is to import functions by name (`import Html exposing (div, span)`) or to use qualified imports (`import Html`, then `Html.div`). If the module name is too long, you can give an alias to the imported module (`import Html.Attributes as Attr`)."
]
tests : List Test
tests =
[ test "should not report imports that do not expose anything" <|
@ -34,6 +41,7 @@ import Html exposing (..)"""
|> Lint.Test.expectErrors
[ Lint.Test.error
{ message = "Do not expose everything from Html"
, details = details
, under = ".."
}
|> Lint.Test.atExactly { start = { row = 2, column = 23 }, end = { row = 2, column = 25 } }
@ -46,6 +54,7 @@ import Html.App exposing (..)"""
|> Lint.Test.expectErrors
[ Lint.Test.error
{ message = "Do not expose everything from Html.App"
, details = details
, under = ".."
}
]
@ -57,6 +66,7 @@ import Html.Foo.Bar exposing (..)"""
|> Lint.Test.expectErrors
[ Lint.Test.error
{ message = "Do not expose everything from Html.Foo.Bar"
, details = details
, under = ".."
}
]
@ -86,6 +96,7 @@ import Html.Foo.Bar exposing (..)"""
|> Lint.Test.expectErrors
[ Lint.Test.error
{ message = "Do not expose everything from Html.Foo.Bar"
, details = details
, under = ".."
}
]
@ -97,6 +108,7 @@ import Html exposing (..)"""
|> Lint.Test.expectErrors
[ Lint.Test.error
{ message = "Do not expose everything from Html"
, details = details
, under = ".."
}
]

View File

@ -10,6 +10,12 @@ testRule =
Lint.Test.run rule
details : List String
details =
[ "Since it is not being used, I recommend removing it. It should make the code clearer to read for other people."
]
tests : List Test
tests =
[ test "should not report non-exposed variables" <|
@ -43,10 +49,12 @@ type Foo = Bar | Baz"""
|> Lint.Test.expectErrors
[ Lint.Test.error
{ message = "Type constructor `Bar` is not used."
, details = details
, under = "Bar"
}
, Lint.Test.error
{ message = "Type constructor `Baz` is not used."
, details = details
, under = "Baz"
}
]
@ -57,10 +65,12 @@ type Foo = Bar | Baz"""
|> Lint.Test.expectErrors
[ Lint.Test.error
{ message = "Type constructor `Bar` is not used."
, details = details
, under = "Bar"
}
, Lint.Test.error
{ message = "Type constructor `Baz` is not used."
, details = details
, under = "Baz"
}
]

View File

@ -10,6 +10,11 @@ testRule =
Lint.Test.run rule
details : List String
details =
[ "Since it is not being used, I recommend removing it. It should make the code clearer to read for other people." ]
all : Test
all =
describe "NoUnusedVariables"
@ -47,6 +52,7 @@ a = 1"""
|> Lint.Test.expectErrors
[ Lint.Test.error
{ message = "Variable `a` is not used"
, details = details
, under = "a"
}
]
@ -58,6 +64,7 @@ a = 1"""
|> Lint.Test.expectErrors
[ Lint.Test.error
{ message = "Variable `a` is not used"
, details = details
, under = "a"
}
|> Lint.Test.atExactly { start = { row = 3, column = 1 }, end = { row = 3, column = 2 } }
@ -83,6 +90,7 @@ c = 3"""
|> Lint.Test.expectErrors
[ Lint.Test.error
{ message = "Variable `c` is not used"
, details = details
, under = "c"
}
]
@ -107,6 +115,7 @@ c = 3"""
|> Lint.Test.expectErrors
[ Lint.Test.error
{ message = "Variable `c` is not used"
, details = details
, under = "c"
}
]
@ -118,6 +127,7 @@ a = Html.Styled.Attributes.href"""
|> Lint.Test.expectErrors
[ Lint.Test.error
{ message = "Variable `href` is not used"
, details = details
, under = "href"
}
|> Lint.Test.atExactly { start = { row = 2, column = 1 }, end = { row = 2, column = 5 } }
@ -135,6 +145,7 @@ a = let b = 1
|> Lint.Test.expectErrors
[ Lint.Test.error
{ message = "Variable `b` is not used"
, details = details
, under = "b"
}
]
@ -146,6 +157,7 @@ a = let b = 1
|> Lint.Test.expectErrors
[ Lint.Test.error
{ message = "Variable `b` is not used"
, details = details
, under = "b"
}
|> Lint.Test.atExactly { start = { row = 2, column = 9 }, end = { row = 2, column = 10 } }
@ -158,6 +170,7 @@ a = let b param = 1
|> Lint.Test.expectErrors
[ Lint.Test.error
{ message = "Variable `b` is not used"
, details = details
, under = "b"
}
|> Lint.Test.atExactly { start = { row = 2, column = 9 }, end = { row = 2, column = 10 } }
@ -170,6 +183,7 @@ a = let b = 1
|> Lint.Test.expectErrors
[ Lint.Test.error
{ message = "Variable `b` is not used"
, details = details
, under = "b"
}
]
@ -239,6 +253,7 @@ a = { b | c = 3 }"""
|> Lint.Test.expectErrors
[ Lint.Test.error
{ message = "Variable `c` is not used"
, details = details
, under = "c"
}
|> Lint.Test.atExactly { start = { row = 3, column = 1 }, end = { row = 3, column = 2 } }
@ -265,6 +280,7 @@ import Foo exposing (a)"""
|> Lint.Test.expectErrors
[ Lint.Test.error
{ message = "Imported variable `a` is not used"
, details = details
, under = "a"
}
]
@ -275,14 +291,17 @@ import Foo exposing (C, a, b)"""
|> Lint.Test.expectErrors
[ Lint.Test.error
{ message = "Imported type `C` is not used"
, details = details
, under = "C"
}
, Lint.Test.error
{ message = "Imported variable `a` is not used"
, details = details
, under = "a"
}
, Lint.Test.error
{ message = "Imported variable `b` is not used"
, details = details
, under = "b"
}
]
@ -293,6 +312,7 @@ import Parser exposing ((</>))"""
|> Lint.Test.expectErrors
[ Lint.Test.error
{ message = "Imported operator `</>` is not used"
, details = details
, under = "(</>)"
}
]
@ -303,6 +323,7 @@ import Html"""
|> Lint.Test.expectErrors
[ Lint.Test.error
{ message = "Imported module `Html` is not used"
, details = details
, under = "Html"
}
]
@ -313,6 +334,7 @@ import Html.Styled.Attributes"""
|> Lint.Test.expectErrors
[ Lint.Test.error
{ message = "Imported module `Html.Styled.Attributes` is not used"
, details = details
, under = "Html.Styled.Attributes"
}
]
@ -340,6 +362,7 @@ import Html.Styled.Attributes as Html"""
|> Lint.Test.expectErrors
[ Lint.Test.error
{ message = "Module alias `Html` is not used"
, details = details
, under = "Html"
}
|> Lint.Test.atExactly { start = { row = 2, column = 34 }, end = { row = 2, column = 38 } }
@ -353,6 +376,7 @@ a = ()"""
|> Lint.Test.expectErrors
[ Lint.Test.error
{ message = "Module alias `Html` is not used"
, details = details
, under = "Html"
}
|> Lint.Test.atExactly { start = { row = 2, column = 34 }, end = { row = 2, column = 38 } }
@ -366,6 +390,7 @@ a = ()"""
|> Lint.Test.expectErrors
[ Lint.Test.error
{ message = "Module alias `Html` is not used"
, details = details
, under = "Html"
}
|> Lint.Test.atExactly { start = { row = 2, column = 23 }, end = { row = 2, column = 27 } }
@ -445,6 +470,7 @@ type A = B | C"""
|> Lint.Test.expectErrors
[ Lint.Test.error
{ message = "Type `A` is not used"
, details = details
, under = "A"
}
|> Lint.Test.atExactly { start = { row = 2, column = 6 }, end = { row = 2, column = 7 } }
@ -462,6 +488,7 @@ type alias A = { a : B }"""
|> Lint.Test.expectErrors
[ Lint.Test.error
{ message = "Type `A` is not used"
, details = details
, under = "A"
}
|> Lint.Test.atExactly { start = { row = 2, column = 12 }, end = { row = 2, column = 13 } }
@ -644,6 +671,7 @@ type A a = B a"""
|> Lint.Test.expectErrors
[ Lint.Test.error
{ message = "Variable `a` is not used"
, details = details
, under = "a"
}
|> Lint.Test.atExactly { start = { row = 2, column = 1 }, end = { row = 2, column = 2 } }
@ -657,6 +685,7 @@ a str = {c = str}"""
|> Lint.Test.expectErrors
[ Lint.Test.error
{ message = "Variable `r` is not used"
, details = details
, under = "r"
}
|> Lint.Test.atExactly { start = { row = 2, column = 1 }, end = { row = 2, column = 2 } }
@ -673,6 +702,7 @@ type A = A Int"""
|> Lint.Test.expectErrors
[ Lint.Test.error
{ message = "Type `A` is not used"
, details = details
, under = "A"
}
|> Lint.Test.atExactly { start = { row = 2, column = 6 }, end = { row = 2, column = 7 } }
@ -722,6 +752,7 @@ port input : (Json.Decode.Value -> msg) -> Sub msg"""
|> Lint.Test.expectErrors
[ Lint.Test.error
{ message = "Port `input` is not used (Warning: Removing this port may break your application if it is used in the JS code)"
, details = details
, under = "input"
}
]
@ -733,6 +764,7 @@ port output : Json.Encode.Value -> Cmd msg"""
|> Lint.Test.expectErrors
[ Lint.Test.error
{ message = "Port `output` is not used (Warning: Removing this port may break your application if it is used in the JS code)"
, details = details
, under = "output"
}
]