Remove tests for removed rules

This commit is contained in:
Jeroen Engels 2018-11-05 15:41:12 +01:00
parent 9e6b1e52c4
commit a633af02b2
13 changed files with 0 additions and 1303 deletions

View File

@ -1,96 +0,0 @@
module DefaultPatternPositionTest exposing (all)
import Lint.Rules.DefaultPatternPosition exposing (Configuration, PatternPosition(..), rule)
import Lint.Types exposing (LintError, LintResult, LintRule)
import Test exposing (Test, describe, test)
import TestUtil exposing (expectErrors, ruleTester)
testRule : Configuration -> String -> LintResult
testRule options =
ruleTester (rule options)
error : String -> LintError
error position =
LintError "DefaultPatternPosition" ("Expected default pattern to appear " ++ position ++ " in the list of patterns")
tests : List Test
tests =
[ test "should not report when default pattern is at the expected position (first)" <|
\() ->
"""a = case b of
_ -> 1
Bar -> 1
Foo -> 1
"""
|> testRule { position = First }
|> expectErrors []
, test "should not report when default pattern is at the expected position (last)" <|
\() ->
"""a = case b of
Foo -> 1
Bar -> 1
_ -> 1
"""
|> testRule { position = Last }
|> expectErrors []
, test "should not report when there is no default pattern (first)" <|
\() ->
"""a = case b of
Foo -> 1
Bar -> 1
"""
|> testRule { position = First }
|> expectErrors []
, test "should not report when there is no default pattern (last)" <|
\() ->
"""a = case b of
Foo -> 1
Bar -> 1
"""
|> testRule { position = Last }
|> expectErrors []
, test "should report an error when the default pattern is not at the expected position (first) (opposite expected position)" <|
\() ->
"""a = case b of
Foo -> 1
Bar -> 1
_ -> 1
"""
|> testRule { position = First }
|> expectErrors [ error "first" ]
, test "should report an error when the default pattern is not at the expected position (first) (somewhere in the middle)" <|
\() ->
"""a = case b of
Foo -> 1
_ -> 1
Bar -> 1
"""
|> testRule { position = First }
|> expectErrors [ error "first" ]
, test "should report an error when the default pattern is not at the expected position (last) (opposite expected position)" <|
\() ->
"""a = case b of
_ -> 1
Foo -> 1
Bar -> 1
"""
|> testRule { position = Last }
|> expectErrors [ error "last" ]
, test "should report an error when the default pattern is not at the expected position (last) (somewhere in the middle)" <|
\() ->
"""a = case b of
Foo -> 1
_ -> 1
Bar -> 1
"""
|> testRule { position = Last }
|> expectErrors [ error "last" ]
]
all : Test
all =
describe "DefaultPatternPosition" tests

View File

@ -1,178 +0,0 @@
module NoConstantConditionTest exposing (all)
import Lint.Rules.NoConstantCondition exposing (rule)
import Lint.Types exposing (LintError, LintResult, LintRule)
import Test exposing (Test, describe, test)
import TestUtil exposing (expectErrors, ruleTester)
testRule : String -> LintResult
testRule =
ruleTester rule
error : LintError
error =
LintError "NoConstantCondition" "Useless condition: It will always evaluate to the same value"
condition : String -> String
condition expr =
"a = if " ++ expr ++ " then 1 else 0"
comparisonOperators : List String
comparisonOperators =
[ "==", "/=", "<", "<=", ">", ">=" ]
createComparisonSource : String -> String
createComparisonSource op =
String.join "\n"
[ condition ("b " ++ op ++ " c")
, condition ("b " ++ op ++ " 0")
, condition ("0 " ++ op ++ " b")
]
validComparisonTests : List Test
validComparisonTests =
List.map
(\op ->
test ("should not report a condition that compares a variable (" ++ op ++ ")") <|
\() ->
testRule (createComparisonSource op)
|> expectErrors []
)
comparisonOperators
tests : List Test
tests =
[ test "should not report a condition that accesses a variable" <|
\() ->
condition "b"
|> testRule
|> expectErrors []
, test "should not report a condition that calls a function" <|
\() ->
condition "b c"
|> testRule
|> expectErrors []
, test "should not report a condition that compares different lists" <|
\() ->
condition "[a] == [b]"
|> testRule
|> expectErrors []
, test "should not report a condition that compares different records" <|
\() ->
condition "{a = 1} == {a = 2}"
|> testRule
|> expectErrors []
, test "should report condition that only has True" <|
\() ->
condition "True"
|> testRule
|> expectErrors [ error ]
, test "should report condition that only has False" <|
\() ->
condition "False"
|> testRule
|> expectErrors [ error ]
, test "should report condition that compares True to False (==)" <|
\() ->
condition "True == False"
|> testRule
|> expectErrors [ error ]
, test "should report condition that compares True to False (/=)" <|
\() ->
condition "True /= False"
|> testRule
|> expectErrors [ error ]
, test "should report condition that compares False to True (==)" <|
\() ->
condition "False == True"
|> testRule
|> expectErrors [ error ]
, test "should report condition that compares False to True (/=)" <|
\() ->
condition "False /= True"
|> testRule
|> expectErrors [ error ]
, test "should report condition that compares two integers (==)" <|
\() ->
condition "1 == 1"
|> testRule
|> expectErrors [ error ]
, test "should report condition that compares two integers (/=)" <|
\() ->
condition "1 /= 1"
|> testRule
|> expectErrors [ error ]
, test "should report condition that compares two floats (==)" <|
\() ->
condition "1.1 == 1.1"
|> testRule
|> expectErrors [ error ]
, test "should report condition that compares two floats (/=)" <|
\() ->
condition "1.1 /= 1.1"
|> testRule
|> expectErrors [ error ]
, test "should report condition that compares two strings (==)" <|
\() ->
condition "\"foo\" == \"foo\""
|> testRule
|> expectErrors [ error ]
, test "should report condition that compares two strings (/=)" <|
\() ->
condition "\"foo\" /= \"foo\""
|> testRule
|> expectErrors [ error ]
, test "should report condition that compares two similar Lists (==)" <|
\() ->
condition "[1, 2] == [1, 2]"
|> testRule
|> expectErrors [ error ]
, test "should report condition that compares two similar Lists (/=)" <|
\() ->
condition "[1, 2] /= [1, 2]"
|> testRule
|> expectErrors [ error ]
, test "should report condition that compares two similar Lists, even with variables" <|
\() ->
condition "[1, a] == [1, a]"
|> testRule
|> expectErrors [ error ]
, test "should report condition that compares two similar records" <|
\() ->
condition "{ a = 2 } == { a = 2 }"
|> testRule
|> expectErrors [ error ]
, test "should report condition that compares two identical elements (==)" <|
\() ->
condition "b == b"
|> testRule
|> expectErrors [ error ]
, test "should report condition that compares two identical elements (/=)" <|
\() ->
condition "b /= b"
|> testRule
|> expectErrors [ error ]
, test "should report condition that compares two identical complex elements (==)" <|
\() ->
condition "((foo bar) ++ List.map a <| List.reduce b c d) == ((foo bar) ++ List.map a <| List.reduce b c d)"
|> testRule
|> expectErrors [ error ]
, test "should report condition that compares two identical complex elements (/=)" <|
\() ->
condition "((foo bar) ++ List.map a <| List.reduce b c d) /= ((foo bar) ++ List.map a <| List.reduce b c d)"
|> testRule
|> expectErrors [ error ]
]
++ validComparisonTests
all : Test
all =
describe "NoConstantCondition" tests

View File

@ -1,105 +0,0 @@
module NoDuplicateImportsTest exposing (all)
import Lint.Rules.NoDuplicateImports exposing (rule)
import Lint.Types exposing (LintError, LintResult, LintRule)
import Test exposing (Test, describe, test)
import TestUtil exposing (expectErrors, ruleTester)
testRule : String -> LintResult
testRule =
ruleTester rule
error : String -> LintError
error =
LintError "NoDuplicateImports"
tests : List Test
tests =
[ test "should not report imports that are called only once" <|
\() ->
testRule """
import Regex
import Http
import Html exposing (..)
import Lib exposing (a)
"""
|> expectErrors []
, test "should report duplicated imports" <|
\() ->
testRule """
import Regex
import Regex
import Http
"""
|> expectErrors [ error "Regex was imported several times" ]
, test "should report duplicated imports when several modules are imported twice" <|
\() ->
testRule """
import Regex
import Regex
import Http
import Http
"""
|> expectErrors
[ error "Http was imported several times"
, error "Regex was imported several times"
]
, test "should only report duplicated imports once" <|
\() ->
testRule """
import Regex
import Regex
import Regex
"""
|> expectErrors [ error "Regex was imported several times" ]
, test "should report duplicated imports even if they do not import the same thing (1)" <|
\() ->
testRule """
import Regex
import Regex exposing (a)
"""
|> expectErrors [ error "Regex was imported several times" ]
, test "should report duplicated imports even if they do not import the same thing (2)" <|
\() ->
testRule """
import Regex
import Regex exposing (..)
"""
|> expectErrors [ error "Regex was imported several times" ]
, test "should report duplicated imports even if they do not import the same thing (3)" <|
\() ->
testRule """
import Regex exposing (..)
import Regex exposing (a)
"""
|> expectErrors [ error "Regex was imported several times" ]
, test "should report duplicated imports even if they do not import the same thing (4)" <|
\() ->
testRule """
import Regex exposing (a)
import Regex exposing (b)
"""
|> expectErrors [ error "Regex was imported several times" ]
, test "should report duplicated submodule imports" <|
\() ->
testRule """
import Html.App
import Html.App
"""
|> expectErrors [ error "Html.App was imported several times" ]
, test "should not report the import of a module and its submodule" <|
\() ->
testRule """
import Html
import Html.App
"""
|> expectErrors []
]
all : Test
all =
describe "NoDuplicateImports" tests

View File

@ -1,68 +0,0 @@
module NoExposingEverythingTest exposing (all)
import Lint.Rules.NoExposingEverything exposing (rule)
import Lint.Types exposing (LintError, LintResult, LintRule)
import Test exposing (Test, describe, test)
import TestUtil exposing (expectErrors, ruleTester)
testRule : String -> LintResult
testRule =
ruleTester rule
error : String -> LintError
error =
LintError "NoExposingEverything"
tests : List Test
tests =
[ test "should not report modules that do not have a module declaration" <|
\() ->
testRule "bar = 2"
|> expectErrors []
, test "should not report import statements that expose everything" <|
\() ->
testRule """module Foo exposing (foo)
import Html exposing (..)
"""
|> expectErrors []
, test "should not report modules that expose discrete items (single item)" <|
\() ->
testRule "module Foo exposing (foo)"
|> expectErrors []
, test "should not report modules that expose discrete items (multiple items)" <|
\() ->
testRule "module Foo exposing (foo, bar)"
|> expectErrors []
, test "should not report port modules that expose discrete items (single item)" <|
\() ->
testRule "port module Foo exposing (foo)"
|> expectErrors []
, test "should not report port modules that expose discrete items (multiple items)" <|
\() ->
testRule "port module Foo exposing (foo, bar)"
|> expectErrors []
, test "should report modules that expose everything" <|
\() ->
testRule "module Foo exposing (..)"
|> expectErrors [ error "Do not expose everything from module Foo using (..)" ]
, test "should report port modules that expose everything" <|
\() ->
testRule "port module Foo exposing (..)"
|> expectErrors [ error "Do not expose everything from module Foo using (..)" ]
, test "should report modules with dotted names that expose everything" <|
\() ->
testRule "module Foo.Bar.Baz exposing (..)"
|> expectErrors [ error "Do not expose everything from module Foo.Bar.Baz using (..)" ]
, test "should report port modules with dotted names that expose everything" <|
\() ->
testRule "port module Foo.Bar.Baz exposing (..)"
|> expectErrors [ error "Do not expose everything from module Foo.Bar.Baz using (..)" ]
]
all : Test
all =
describe "NoExposingEverything" tests

View File

@ -1,78 +0,0 @@
module NoImportingEverythingTest exposing (all)
import Lint.Rules.NoImportingEverything exposing (Configuration, rule)
import Lint.Types exposing (LintError, LintResult, LintRule)
import Test exposing (Test, describe, test)
import TestUtil exposing (expectErrors, ruleTester)
testRule : Configuration -> String -> LintResult
testRule options =
ruleTester (rule options)
error : String -> LintError
error =
LintError "NoImportingEverything"
tests : List Test
tests =
[ test "should not report imports that do not expose anything" <|
\() ->
"""
import Html
import Http
"""
|> testRule { exceptions = [] }
|> expectErrors []
, test "should not report imports that expose functions by name" <|
\() ->
"""
import Html exposing (a)
import Http exposing (a, b)
"""
|> testRule { exceptions = [] }
|> expectErrors []
, test "should report imports that expose everything" <|
\() ->
"import Html exposing (..)"
|> testRule { exceptions = [] }
|> expectErrors
[ error "Do not expose everything from Html" ]
, test "should report imports from sub-modules" <|
\() ->
"import Html.App exposing (..)"
|> testRule { exceptions = [] }
|> expectErrors [ error "Do not expose everything from Html.App" ]
, test "should report imports from sub-modules (multiple dots)" <|
\() ->
"import Html.Foo.Bar exposing (..)"
|> testRule { exceptions = [] }
|> expectErrors [ error "Do not expose everything from Html.Foo.Bar" ]
, test "should not report imports that expose everything that are in the exception list" <|
\() ->
"import Html exposing (..)"
|> testRule { exceptions = [ "Html" ] }
|> expectErrors []
, test "should not report imports from sub-modules that are in the exception list" <|
\() ->
"import Html.App exposing (..)"
|> testRule { exceptions = [ "Html.App" ] }
|> expectErrors []
, test "should not report imports from sub-modules (multiple dots)" <|
\() ->
"import Html.Foo.Bar exposing (..)"
|> testRule { exceptions = [ "Html.Foo.Bar" ] }
|> expectErrors []
, test "should not report when declaring a module that exposes everything" <|
\() ->
"module Main exposing (..)"
|> testRule { exceptions = [] }
|> expectErrors []
]
all : Test
all =
describe "NoImportingEverything" tests

View File

@ -1,48 +0,0 @@
module NoNestedLetTest exposing (all)
import Lint.Rules.NoNestedLet exposing (rule)
import Lint.Types exposing (LintError, LintResult, LintRule)
import Test exposing (Test, describe, test)
import TestUtil exposing (expectErrors, ruleTester)
testRule : String -> LintResult
testRule =
ruleTester rule
error : LintError
error =
LintError "NoNestedLet" "Do not nest Let expressions directly"
tests : List Test
tests =
[ test "should not report single let expression" <|
\() ->
testRule """a = let b = 1
in b
"""
|> expectErrors []
, test "should report let expression inside the body of an other let expression" <|
\() ->
testRule """a = let b = 1
in let c = 2
in c
"""
|> expectErrors [ error ]
, test "should not report let expression indirectly inside another " <|
\() ->
testRule """a = let b = 1
in if foo then
let c = 2 in c
else
3
"""
|> expectErrors []
]
all : Test
all =
describe "NoNestedLet" tests

View File

@ -1,75 +0,0 @@
module NoUnannotatedFunctionTest exposing (all)
import Lint.Rules.NoUnannotatedFunction exposing (rule)
import Lint.Types exposing (LintError, LintResult, LintRule)
import Test exposing (Test, describe, test)
import TestUtil exposing (expectErrors, ruleTester)
testRule : String -> LintResult
testRule =
ruleTester rule
error : String -> LintError
error =
LintError "NoUnannotatedFunction"
tests : List Test
tests =
[ test "should not report constants that are annotated" <|
\() ->
testRule """
f : Int
f = 2
"""
|> expectErrors []
, test "should not report functions that are annotated" <|
\() ->
testRule """
f : Int -> Int
f n = 2
"""
|> expectErrors []
, test "should report constants that are not annotated" <|
\() ->
testRule "f = 2"
|> expectErrors [ error "`f` does not have a type declaration" ]
, test "should report functions that are not annotated" <|
\() ->
testRule "f n = 2"
|> expectErrors [ error "`f` does not have a type declaration" ]
, test "should report functions that are not annotated when there are annotations" <|
\() ->
testRule """
f : Int -> Int
g n = 3
"""
|> expectErrors [ error "`g` does not have a type declaration" ]
, test "should report functions that are not annotated when there are other annotated functions" <|
\() ->
testRule """
f : Int -> Int
f n = 2
g n = 3
"""
|> expectErrors [ error "`g` does not have a type declaration" ]
, test "should not functions declared in a `let` body" <|
\() ->
testRule """
f : Int -> Int
f n =
let
a = 2
in
a
"""
|> expectErrors []
]
all : Test
all =
describe "NoUnannotatedFunction" tests

View File

@ -1,243 +0,0 @@
module NoUnusedVariablesTest exposing (all)
import Lint.Rules.NoUnusedVariables exposing (rule)
import Lint.Types exposing (LintError, LintResult, LintRule)
import Test exposing (Test, describe, test)
import TestUtil exposing (expectErrors, ruleTester)
testRule : String -> LintResult
testRule =
ruleTester rule
error : String -> LintError
error =
LintError "NoUnusedVariables"
tests : List Test
tests =
[ test "should not report used top-level variables" <|
\() ->
testRule """module A exposing (b)
a n = 1
b = a 1
"""
|> expectErrors []
, test "should report unused top-level variables" <|
\() ->
testRule "a = 1"
|> expectErrors [ error "Variable `a` is not used" ]
, test "should report unused top-level variables even if they are annotated" <|
\() ->
testRule """
a: Int
a = 1
"""
|> expectErrors [ error "Variable `a` is not used" ]
, test "should not report unused top-level variables if everything is exposed" <|
\() ->
testRule """module A exposing (..)
a n = 1
b = a 1
"""
|> expectErrors []
, test "should not report unused top-level variables that are exposed by name" <|
\() ->
testRule """module A exposing (a, b)
a = 1
b = 2
"""
|> expectErrors []
, test "should not report unused top-level variables that are exposed by name, but report others" <|
\() ->
testRule """module A exposing (a, b)
a = 1
b = 2
c = 3
"""
|> expectErrors [ error "Variable `c` is not used" ]
, test "should not report unused top-level variables if everything is exposed (port module)" <|
\() ->
testRule """port module A exposing (..)
a n = 1
b = a 1
"""
|> expectErrors []
, test "should not report unused top-level variables that are exposed by name (port module)" <|
\() ->
testRule """port module A exposing (a, b)
a = 1
b = 2
"""
|> expectErrors []
, test "should not report unused top-level variables that are exposed by name, but report others (port module)" <|
\() ->
testRule """port module A exposing (a, b)
a = 1
b = 2
c = 3
"""
|> expectErrors [ error "Variable `c` is not used" ]
, test "should report unused variables from let declarations" <|
\() ->
testRule """module A exposing (a)
a = let b = 1
in 2
"""
|> expectErrors [ error "Variable `b` is not used" ]
, test "should report unused variables from let even if they are exposed by name" <|
\() ->
testRule """module A exposing (a, b)
a = let b = 1
in 2
"""
|> expectErrors [ error "Variable `b` is not used" ]
, test "should report unused functions from let even if they are exposed by name" <|
\() ->
testRule """module A exposing (a)
a = let b param = 1
in 2
"""
|> expectErrors [ error "Variable `b` is not used" ]
, test "should report unused variables from let even if everything is exposed" <|
\() ->
testRule """module A exposing (..)
a = let b = 1
in 2
"""
|> expectErrors [ error "Variable `b` is not used" ]
, test "should not report top-level variables used inside a let body" <|
\() ->
testRule """module A exposing (a)
b = 1
a = let c = 1
in b + c
"""
|> expectErrors []
, test "should not report top-level variables used inside let declarations" <|
\() ->
testRule """module A exposing (a)
b = 1
a = let c = b
in c
"""
|> expectErrors []
, test "should not report top-level variables used in nested lets" <|
\() ->
testRule """module A exposing (a)
b = 1
a = let
c = b
d = let
e = 1
in
b + c + e
in
d
"""
|> expectErrors []
, test "should not report variables from let declarations that are used in the body" <|
\() ->
testRule """module A exposing (a)
a = let c = 1
in c
"""
|> expectErrors []
, test "should not report unused function parameters" <|
\() ->
testRule """module A exposing (a)
a n = 1
"""
|> expectErrors []
, test "should report unused imported functions" <|
\() ->
testRule "import Foo exposing (a)"
|> expectErrors [ error "Variable `a` is not used" ]
, test "should report unused imported functions (multiple imports)" <|
\() ->
testRule "import Foo exposing (a, b, C)"
|> expectErrors
[ error "Variable `a` is not used"
, error "Variable `b` is not used"
]
-- Needs to be improved, every case should create a new scope stack
-- Right now, every parameter is considered used, which is not great
, test "should not report unused pattern matching parameters" <|
\() ->
testRule """module A exposing (a)
a = case thing of
Foo b c -> []
"""
|> expectErrors []
-- What to do with types needs to be determined when I understand Type exports better (wrt sub-types)
, test "should report unused type declarations" <|
\() ->
testRule """
type A = B | C -- Should B and C be reported if they are not used? Probably.
type alias D = { a : B }
"""
|> expectErrors []
-- , test "should not report unused type declarations if everything is exposed" <|
-- \() ->
-- testRule """module A exposing (a, b)
-- """
-- |> expectErrors [ error "Variable `a` is not used" ]
-- , test "should not report unused type declarations that are exposed by name" <|
-- \() ->
-- testRule """module A exposing (a, b)
-- a = 1
-- b = 2
-- c = 3
-- """
-- |> expectErrors [ error "Variable `a` is not used" ]
-- , test "should report unused named imports `import A exposing (a)`" <|
-- \() ->
-- testRule """module A exposing (a, b)
-- a = 1
-- b = 2
-- c = 3
-- """
-- |> expectErrors [ error "Variable `a` is not used" ]
-- , test "should not report used named imports `import A exposing (a)`" <|
-- \() ->
-- testRule """module A exposing (a, b)
-- a = 1
-- b = 2
-- c = 3
-- """
-- |> expectErrors [ error "Variable `a` is not used" ]
-- , test "should not report unused union imports `import A exposing (B(..))`" <|
-- \() ->
-- testRule """module A exposing (a, b)
-- a = 1
-- b = 2
-- c = 3
-- """
-- |> expectErrors [ error "Variable `a` is not used" ]
-- , test "should report unused union imports `import A exposing (B(B))`" <|
-- \() ->
-- testRule """module A exposing (a, b)
-- a = 1
-- b = 2
-- c = 3
-- """
-- |> expectErrors [ error "Variable `a` is not used" ]
-- , test "should not report unused union imports `import A exposing (B(B))` (with more nesting?)" <|
-- \() ->
-- testRule """module A exposing (a, b)
-- a = 1
-- b = 2
-- c = 3
-- """
-- |> expectErrors [ error "Variable `a` is not used" ]
]
all : Test
all =
describe "NoUnusedVariables" tests

View File

@ -1,38 +0,0 @@
module NoUselessIfTest exposing (all)
import Lint.Rules.NoUselessIf exposing (rule)
import Lint.Types exposing (LintError, LintResult, LintRule)
import Test exposing (Test, describe, test)
import TestUtil exposing (expectErrors, ruleTester)
testRule : String -> LintResult
testRule =
ruleTester rule
error : LintError
error =
LintError "NoUselessIf" "Useless if expression: It will always evaluate to the same value"
tests : List Test
tests =
[ test "should not report If expression that has different values in both paths" <|
\() ->
testRule "a = if b then c else d"
|> expectErrors []
, test "should report If expression that has the same value in both paths" <|
\() ->
testRule "a = if b then c else c"
|> expectErrors [ error ]
, test "should report If expression that has the same complex value in both paths" <|
\() ->
testRule "a = if b then (foo m, bar n p) else (foo m, bar n p)"
|> expectErrors [ error ]
]
all : Test
all =
describe "NoUselessIf" tests

View File

@ -1,124 +0,0 @@
module NoUselessPatternMatchingTest exposing (all)
import Lint.Rules.NoUselessPatternMatching exposing (rule)
import Lint.Types exposing (LintError, LintResult, LintRule)
import Test exposing (Test, describe, test)
import TestUtil exposing (expectErrors, ruleTester)
testRule : String -> LintResult
testRule =
ruleTester rule
uselessError : LintError
uselessError =
LintError "NoUselessPatternMatching" "Useless case expression: It will always evaluate to the same value"
uselessPatternError : LintError
uselessPatternError =
LintError "NoUselessPatternMatching" "Useless patterns: Some will always evaluate to the same value as the default pattern"
tests : List Test
tests =
[ test "should not report cases with different results" <|
\() ->
testRule """a = case b of
Just c -> a
Nothing -> 1
"""
|> expectErrors []
, test "should report case expression where all pattern end up with the same result" <|
\() ->
testRule """a = case b of
Just c -> 1
Nothing -> 1
"""
|> expectErrors [ uselessError ]
, test "should report case expression where all pattern have the same expression" <|
\() ->
testRule """a = case b of
Just c -> b
Nothing -> b
"""
|> expectErrors [ uselessError ]
, test "should not report case expression where all pattern end up with the same body, but introduce and use variables with pattern matching" <|
\() ->
testRule """a = case b of
Just b -> b
Nothing -> b
"""
|> expectErrors []
, test "should report case expression where all pattern end up with the same body, and introduce but don't use variables with pattern matching" <|
\() ->
testRule """a = case b of
Just g c D e -> b
Nothing -> b
"""
|> expectErrors [ uselessError ]
, test "should report patterns that have the same value as the default pattern and do not introduce variables" <|
\() ->
testRule """a = case b of
Foo -> c
Bar -> b
a -> b
"""
|> expectErrors [ uselessPatternError ]
, test "should report patterns that have the same value as the default pattern and do not introduce variables (with _)" <|
\() ->
testRule """a = case foo of
Nothing -> 2
Just -> 1
_ -> 1
"""
|> expectErrors [ uselessPatternError ]
, test "should not report patterns that have the same value as the default pattern but introduce and use variables" <|
\() ->
testRule """a = case b of
Foo -> c
Bar b -> b
a -> b
"""
|> expectErrors []
, test "should report patterns that have the same value as the default pattern, even if they introduce and don't use variables" <|
\() ->
testRule """a = case b of
Foo -> c
Bar d -> b
a -> b
"""
|> expectErrors [ uselessPatternError ]
, test "should not report patterns where there is no default pattern" <|
\() ->
testRule """a = case b of
Foo -> c
Bar -> b
Baz -> b
"""
|> expectErrors []
, test "should not report case where there is only one pattern (which introduces and uses variables)" <|
\() ->
testRule """a = case b of
Foo d -> d
"""
|> expectErrors []
, test "should report case where there is only one pattern (which doesn't have variables)" <|
\() ->
testRule """a = case b of
Foo -> d
"""
|> expectErrors [ uselessError ]
, test "should report case where there is only the default pattern" <|
\() ->
testRule """a = case b of
_ -> d
"""
|> expectErrors [ uselessError ]
]
all : Test
all =
describe "NoUselessPatternMatching" tests

View File

@ -1,65 +0,0 @@
module NoWarningCommentsTest exposing (all)
import Lint.Rules.NoWarningComments exposing (rule)
import Lint.Types exposing (LintError, LintResult, LintRule)
import Test exposing (Test, describe, test)
import TestUtil exposing (expectErrors, ruleTester)
testRule : String -> LintResult
testRule =
ruleTester rule
error : String -> LintError
error word =
LintError "NoWarningComments" ("Unexpected " ++ word ++ " comment")
wordsToLookFor : List String
wordsToLookFor =
[ "TODO", "todo", "FIXME", "fixme", "XXX", "xxx" ]
failingTestCases : List Test
failingTestCases =
List.concatMap
(\word ->
[ test ("should report single-line comments containing only " ++ word) <|
\() ->
testRule ("-- " ++ word)
|> expectErrors [ error word ]
, test ("should report single-line comments containing " ++ word) <|
\() ->
testRule ("-- " ++ word ++ ": Do this")
|> expectErrors [ error word ]
, test ("should report single-line comments containing " ++ word ++ " (no space between comment and word)") <|
\() ->
testRule ("--" ++ word ++ ": Do this")
|> expectErrors [ error word ]
, test ("should report multi-line comments containing " ++ word) <|
\() ->
testRule ("{-" ++ word ++ " \n -}")
|> expectErrors [ error word ]
]
)
wordsToLookFor
tests : List Test
tests =
[ test "should not report regular single-line comments" <|
\() ->
testRule "-- foo bar"
|> expectErrors []
, test "should not report regular multi-line comments" <|
\() ->
testRule "{- foo bar \n -}"
|> expectErrors []
]
++ failingTestCases
all : Test
all =
describe "NoWarningComments" tests

View File

@ -1,127 +0,0 @@
module SimplifyPipingTest exposing (all)
import Lint.Rules.SimplifyPiping exposing (rule)
import Lint.Types exposing (LintError, LintResult, LintRule)
import Test exposing (Test, describe, test)
import TestUtil exposing (expectErrors, ruleTester)
testRule : String -> LintResult
testRule =
ruleTester rule
error : String -> String -> LintError
error op fn =
LintError "SimplifyPiping" ("Instead of `" ++ fn ++ " f " ++ op ++ " List.map g`, try " ++ fn ++ " (f " ++ op ++ " g)")
tests : List Test
tests =
[ test "should not report piping of the result of different functions of the same module" <|
\() ->
testRule "a = b |> List.map f |> List.filter g"
|> expectErrors []
, test "should not report piping of the result of similarly named functions of different modules" <|
\() ->
testRule "a = b |> List.map f |> Set.map g"
|> expectErrors []
, test "should report piping of List.map" <|
\() ->
testRule "a = b |> List.map f |> List.map g"
|> expectErrors [ error ">>" "List.map" ]
, test "should report piping of Set.map" <|
\() ->
testRule "a = b |> Set.map f |> Set.map g"
|> expectErrors [ error ">>" "Set.map" ]
, test "should report piping of Array.map" <|
\() ->
testRule "a = b |> Array.map f |> Array.map g"
|> expectErrors [ error ">>" "Array.map" ]
, test "should report piping of the result of Array.indexedMap" <|
\() ->
testRule "a = b |> Array.indexedMap f |> Array.indexedMap g"
|> expectErrors [ error ">>" "Array.indexedMap" ]
, test "should not report piping of the incomplete simplifiable function call" <|
\() ->
testRule "a = List.map f |> List.map g"
|> expectErrors []
, test "should report piping the complete call into the same function" <|
\() ->
testRule "a = List.map f data |> List.map g"
|> expectErrors [ error ">>" "List.map" ]
, test "should report piping the complete call into the same function with an additional pipe at the end" <|
\() ->
testRule "a = List.map f data |> List.map g |> foo"
|> expectErrors [ error ">>" "List.map" ]
, test "should not report the use of a single simplifiable function" <|
\() ->
testRule "a = List.map f"
|> expectErrors []
, test "should not report the use of a single simplifiable function with piped functions as the argument" <|
\() ->
testRule "a = List.map (f >> g)"
|> expectErrors []
, test "should not report any piping of similar methods" <|
\() ->
testRule "a = List.foo fn |> List.foo fn2"
|> expectErrors []
, test "should not report direct piping of List.map and friends" <|
\() ->
testRule """
a = List.map |> List.map
b = List.map >> List.map
c = Set.map |> Set.map
d = Set.map >> Set.map
"""
|> expectErrors []
, test "should report piping right to left" <|
\() ->
testRule "a = List.map f <| List.map g <| b"
|> expectErrors [ error "<<" "List.map" ]
, test "should report piping right to left with complete call at the right side" <|
\() ->
testRule "a = List.map f <| List.map g data"
|> expectErrors [ error "<<" "List.map" ]
, test "should report piping right to left with complete call at the right side and additional pipe on the left" <|
\() ->
testRule "a = a <| List.map f <| List.map g data"
|> expectErrors [ error "<<" "List.map" ]
, test "should report piping the functions directly" <|
\() ->
testRule "a = List.map f >> List.map g"
|> expectErrors [ error ">>" "List.map" ]
, test "should report piping the functions directly with additional pipe on the left" <|
\() ->
testRule "a = foo >> List.map f >> List.map g"
|> expectErrors [ error ">>" "List.map" ]
, test "should report piping the functions directly with additional pipe on the right" <|
\() ->
testRule "a = List.map f >> List.map g >> bar"
|> expectErrors [ error ">>" "List.map" ]
, test "should report piping the functions directly with additional pipe on both sides" <|
\() ->
testRule "a = foo >> List.map f >> List.map g >> bar"
|> expectErrors [ error ">>" "List.map" ]
, test "should report piping the functions directly, right to left" <|
\() ->
testRule "a = List.map f << List.map g"
|> expectErrors [ error "<<" "List.map" ]
, test "should report piping the functions directly with additional pipe on the left, right to left" <|
\() ->
testRule "a = foo << List.map f << List.map g"
|> expectErrors [ error "<<" "List.map" ]
, test "should report piping the functions directly with additional pipe on the right, right to left" <|
\() ->
testRule "a = List.map f << List.map g << bar"
|> expectErrors [ error "<<" "List.map" ]
, test "should report piping the functions directly with additional pipe on both sides, right to left" <|
\() ->
testRule "a = foo << List.map f << List.map g << bar"
|> expectErrors [ error "<<" "List.map" ]
]
all : Test
all =
describe "SimplifyPiping" tests

View File

@ -1,58 +0,0 @@
module SimplifyPropertyAccessTest exposing (all)
import Lint.Rules.SimplifyPropertyAccess exposing (rule)
import Lint.Types exposing (LintError, LintResult, LintRule)
import Test exposing (Test, describe, test)
import TestUtil exposing (expectErrors, ruleTester)
testRule : String -> LintResult
testRule =
ruleTester rule
error : String -> LintError
error =
LintError "SimplifyPropertyAccess"
tests : List Test
tests =
[ test "should report a named function that returns the property of a record" <|
\() ->
testRule "a x = x.foo"
|> expectErrors [ error "Access to property `foo` could be simplified by using `.foo`" ]
, test "should report an anonymous function that returns the property of a record" <|
\() ->
testRule "a = List.map (\\x -> x.foo)"
|> expectErrors [ error "Access to property `foo` could be simplified by using `.foo`" ]
, test "should not report a named function that returns a nested property" <|
\() ->
testRule "a x = x.foo.bar"
|> expectErrors []
, test "should not report an anonymous function that returns a nested property" <|
\() ->
testRule "a = List.map (\\x -> x.foo.bar)"
|> expectErrors []
, test "should not report a named function that returns the property of another value" <|
\() ->
testRule "a x = b.foo"
|> expectErrors []
, test "should not report an anonymous function that returns the property of another value" <|
\() ->
testRule "a = List.map (\\x -> b.foo)"
|> expectErrors []
, test "should not report a named function that has multiple parameters" <|
\() ->
testRule "a x y = x.foo"
|> expectErrors []
, test "should not report an anonymous function that has multiple parameters" <|
\() ->
testRule "a = List.map (\\x y -> x.foo)"
|> expectErrors []
]
all : Test
all =
describe "SimplifyPropertyAccess" tests