Compare commits

...

2 Commits

Author SHA1 Message Date
Jeroen Engels
f45c2aeba4 Split pipelines 2024-09-08 18:44:43 +02:00
Jeroen Engels
9b2b19d2cb Fix invalid syntax in test code 2024-09-08 18:40:23 +02:00
6 changed files with 105 additions and 63 deletions

View File

@ -433,15 +433,17 @@ collectLookupTable declarations context =
visitExpressions : Node Expression -> Context -> Context
visitExpressions node context =
-- IGNORE TCO
context
|> popScopeEnter node
|> expressionEnterVisitor node
|> (\newContext ->
List.foldl
visitExpressions
newContext
(expressionChildren node)
)
let
newContext : Context
newContext =
context
|> popScopeEnter node
|> expressionEnterVisitor node
in
List.foldl
visitExpressions
newContext
(expressionChildren node)
|> popScopeExit node
|> expressionExitVisitor node

View File

@ -5862,16 +5862,19 @@ visitDeclarationsAndExpressions declarations rules =
visitDeclarationAndExpressions : Node Declaration -> JsArray RuleModuleVisitor -> JsArray RuleModuleVisitor
visitDeclarationAndExpressions declaration rules =
rules
|> mutatingMap (\acc -> runVisitor .declarationVisitorOnEnter declaration acc)
|> (\updatedRules ->
case Node.value declaration of
Declaration.FunctionDeclaration function ->
visitExpression (Node.value function.declaration |> .expression) updatedRules
let
updatedRules : JsArray RuleModuleVisitor
updatedRules =
rules
|> mutatingMap (\acc -> runVisitor .declarationVisitorOnEnter declaration acc)
in
(case Node.value declaration of
Declaration.FunctionDeclaration function ->
visitExpression (Node.value function.declaration |> .expression) updatedRules
_ ->
updatedRules
)
_ ->
updatedRules
)
|> mutatingMap (\acc -> runVisitor .declarationVisitorOnExit declaration acc)
@ -5879,38 +5882,44 @@ visitExpression : Node Expression -> JsArray RuleModuleVisitor -> JsArray RuleMo
visitExpression node rules =
case Node.value node of
Expression.LetExpression letBlock ->
rules
|> mutatingMap (\acc -> runVisitor .expressionVisitorOnEnter node acc)
|> (\updatedRules ->
List.foldl
(visitLetDeclaration (Node (Node.range node) letBlock))
updatedRules
letBlock.declarations
)
let
updatedRules : JsArray RuleModuleVisitor
updatedRules =
rules
|> mutatingMap (\acc -> runVisitor .expressionVisitorOnEnter node acc)
in
List.foldl
(visitLetDeclaration (Node (Node.range node) letBlock))
updatedRules
letBlock.declarations
|> visitExpression letBlock.expression
|> mutatingMap (\acc -> runVisitor .expressionVisitorOnExit node acc)
Expression.CaseExpression caseBlock ->
rules
|> mutatingMap (\acc -> runVisitor .expressionVisitorOnEnter node acc)
|> visitExpression caseBlock.expression
|> (\updatedRules ->
List.foldl
(\case_ acc -> visitCaseBranch (Node (Node.range node) caseBlock) case_ acc)
updatedRules
caseBlock.cases
)
let
updatedRules : JsArray RuleModuleVisitor
updatedRules =
rules
|> mutatingMap (\acc -> runVisitor .expressionVisitorOnEnter node acc)
|> visitExpression caseBlock.expression
in
List.foldl
(\case_ acc -> visitCaseBranch (Node (Node.range node) caseBlock) case_ acc)
updatedRules
caseBlock.cases
|> mutatingMap (\acc -> runVisitor .expressionVisitorOnExit node acc)
_ ->
rules
|> mutatingMap (\acc -> runVisitor .expressionVisitorOnEnter node acc)
|> (\updatedRules ->
List.foldl
visitExpression
updatedRules
(expressionChildren node)
)
let
updatedRules : JsArray RuleModuleVisitor
updatedRules =
rules
|> mutatingMap (\acc -> runVisitor .expressionVisitorOnEnter node acc)
in
List.foldl
visitExpression
updatedRules
(expressionChildren node)
|> mutatingMap (\acc -> runVisitor .expressionVisitorOnExit node acc)

View File

@ -1361,6 +1361,7 @@ tests : Test
tests = Test.describe "thing" B.helper
""", """
module B exposing (helper)
{-| Module docs -}
{-| @ignore-helper -}
helper = 1
""" ]

View File

@ -156,6 +156,7 @@ b = 2"""
, test "should report unused top-level variables with documentation attached" <|
\() ->
"""module SomeModule exposing (b)
{-| Module docs -}
{-| Documentation
-}
unusedVar = 1
@ -168,11 +169,13 @@ b = 2"""
, under = "unusedVar"
}
|> Review.Test.whenFixed """module SomeModule exposing (b)
{-| Module docs -}
b = 2"""
]
, test "should report unused top-level variables with documentation attached even if they are annotated" <|
\() ->
"""module SomeModule exposing (b)
{-| Module docs -}
{-| Documentation
-}
unusedVar : Int
@ -185,8 +188,9 @@ b = 2"""
, details = details
, under = "unusedVar"
}
|> Review.Test.atExactly { start = { row = 5, column = 1 }, end = { row = 5, column = 10 } }
|> Review.Test.atExactly { start = { row = 6, column = 1 }, end = { row = 6, column = 10 } }
|> Review.Test.whenFixed """module SomeModule exposing (b)
{-| Module docs -}
b = 2"""
]
, test "should not report unused top-level variables if everything is exposed (functions)" <|
@ -642,7 +646,7 @@ topLevelVariablesUsedInLetInTests =
"""module SomeModule exposing (a)
b = 1
a = let c = 1
in b + c"""
in b + c"""
|> Review.Test.run rule
|> Review.Test.expectNoErrors
, test "should not report top-level variables used inside let declarations" <|
@ -650,21 +654,25 @@ in b + c"""
"""module SomeModule exposing (a)
b = 1
a = let c = b
in c"""
in c
"""
|> Review.Test.run rule
|> Review.Test.expectNoErrors
, test "should not report top-level variables used in nested lets" <|
\() ->
"""module SomeModule exposing (a)
b = 1
a = let
c = b
d = let
e = 1
in
b + c + e
in
d"""
a =
let
c = b
d =
let
e = 1
in
b + c + e
in
d
"""
|> Review.Test.run rule
|> Review.Test.expectNoErrors
]
@ -2016,6 +2024,7 @@ a = 1"""
, test "should report unused custom type declarations with documentation" <|
\() ->
"""module SomeModule exposing (a)
{-| Module docs -}
{-| Documentation -}
type UnusedType = B | C
a = 1"""
@ -2027,6 +2036,7 @@ a = 1"""
, under = "UnusedType"
}
|> Review.Test.whenFixed """module SomeModule exposing (a)
{-| Module docs -}
a = 1"""
]
, test "should report unused custom type declaration even when it references itself" <|
@ -2089,6 +2099,7 @@ a = 1"""
, test "should report unused type aliases declarations with documentation" <|
\() ->
"""module SomeModule exposing (a)
{-| Module docs -}
{-| Documentation -}
type alias UnusedType = { a : B }
a = 1"""
@ -2100,6 +2111,7 @@ a = 1"""
, under = "UnusedType"
}
|> Review.Test.whenFixed """module SomeModule exposing (a)
{-| Module docs -}
a = 1"""
]
, test "should not report type alias used in a signature" <|

View File

@ -143,7 +143,7 @@ Hint: Maybe you forgot to add the module definition at the top, like:
, test "when there are multiple files" <|
\() ->
[ "module MyModule exposing (.."
, "module MyOtherModule exposing (..)"
, "module MyOtherModule exposing (..)\na = 1"
]
|> Review.Test.runOnModules testRuleReportsLiterals
|> Review.Test.expectNoErrors

View File

@ -274,10 +274,19 @@ shiftRange : ( ESN.Node String, Int ) -> { node : ESN.Node String } -> { a | nod
shiftRange input _ _ =
let
asList : ( ESN.Node, Int ) -> List ESN.Node
asList ( node, _ ) = [ node ]
( ESN.Node range1 value1, length1 ) = input
[ ESN.Node range2 value2 ] = asList input
ESN.Node range3 value3 :: [] = asList input
asList ( node, _ ) =
[ node ]
( ESN.Node range value, length1 ) =
case asList input of
[ ESN.Node range2 value2 ] ->
input
ESN.Node range3 value3 :: _ ->
input
_ ->
input
in
range
"""
@ -298,10 +307,19 @@ shiftRange : ( Node.Node String, Int ) -> { node : Node.Node String } -> { a | n
shiftRange input _ _ =
let
asList : ( Node.Node, Int ) -> List Node.Node
asList ( node, _ ) = [ node ]
( Node.Node range1 value1, length1 ) = input
[ Node.Node range2 value2 ] = asList input
Node.Node range3 value3 :: [] = asList input
asList ( node, _ ) =
[ node ]
( Node.Node range value, length1 ) =
case asList input of
[ Node.Node range2 value2 ] ->
input
Node.Node range3 value3 :: _ ->
input
_ ->
input
in
range
"""