mirror of
https://github.com/jfmengels/elm-review.git
synced 2024-11-22 13:15:59 +03:00
Compare commits
4 Commits
03580c904e
...
41b7c0a711
Author | SHA1 | Date | |
---|---|---|---|
|
41b7c0a711 | ||
|
f45c2aeba4 | ||
|
9b2b19d2cb | ||
|
011b4fdb44 |
28
package-lock.json
generated
28
package-lock.json
generated
@ -199,11 +199,11 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/braces": {
|
"node_modules/braces": {
|
||||||
"version": "3.0.2",
|
"version": "3.0.3",
|
||||||
"resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz",
|
||||||
"integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==",
|
"integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"fill-range": "^7.0.1"
|
"fill-range": "^7.1.1"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=8"
|
"node": ">=8"
|
||||||
@ -679,9 +679,9 @@
|
|||||||
"integrity": "sha512-On2N+BpYJ15xIC974QNVuYGMOlEVt4s0EOI3wwMqOmK1fdDY+FN/zltPV8vosq4ad4c/gJ1KHScUn/6AWIgiow=="
|
"integrity": "sha512-On2N+BpYJ15xIC974QNVuYGMOlEVt4s0EOI3wwMqOmK1fdDY+FN/zltPV8vosq4ad4c/gJ1KHScUn/6AWIgiow=="
|
||||||
},
|
},
|
||||||
"node_modules/fill-range": {
|
"node_modules/fill-range": {
|
||||||
"version": "7.0.1",
|
"version": "7.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz",
|
||||||
"integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==",
|
"integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"to-regex-range": "^5.0.1"
|
"to-regex-range": "^5.0.1"
|
||||||
},
|
},
|
||||||
@ -2400,11 +2400,11 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"braces": {
|
"braces": {
|
||||||
"version": "3.0.2",
|
"version": "3.0.3",
|
||||||
"resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz",
|
||||||
"integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==",
|
"integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"fill-range": "^7.0.1"
|
"fill-range": "^7.1.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"buffer": {
|
"buffer": {
|
||||||
@ -2746,9 +2746,9 @@
|
|||||||
"integrity": "sha512-On2N+BpYJ15xIC974QNVuYGMOlEVt4s0EOI3wwMqOmK1fdDY+FN/zltPV8vosq4ad4c/gJ1KHScUn/6AWIgiow=="
|
"integrity": "sha512-On2N+BpYJ15xIC974QNVuYGMOlEVt4s0EOI3wwMqOmK1fdDY+FN/zltPV8vosq4ad4c/gJ1KHScUn/6AWIgiow=="
|
||||||
},
|
},
|
||||||
"fill-range": {
|
"fill-range": {
|
||||||
"version": "7.0.1",
|
"version": "7.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz",
|
||||||
"integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==",
|
"integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"to-regex-range": "^5.0.1"
|
"to-regex-range": "^5.0.1"
|
||||||
}
|
}
|
||||||
|
@ -433,15 +433,17 @@ collectLookupTable declarations context =
|
|||||||
visitExpressions : Node Expression -> Context -> Context
|
visitExpressions : Node Expression -> Context -> Context
|
||||||
visitExpressions node context =
|
visitExpressions node context =
|
||||||
-- IGNORE TCO
|
-- IGNORE TCO
|
||||||
context
|
let
|
||||||
|> popScopeEnter node
|
newContext : Context
|
||||||
|> expressionEnterVisitor node
|
newContext =
|
||||||
|> (\newContext ->
|
context
|
||||||
List.foldl
|
|> popScopeEnter node
|
||||||
visitExpressions
|
|> expressionEnterVisitor node
|
||||||
newContext
|
in
|
||||||
(expressionChildren node)
|
List.foldl
|
||||||
)
|
visitExpressions
|
||||||
|
newContext
|
||||||
|
(expressionChildren node)
|
||||||
|> popScopeExit node
|
|> popScopeExit node
|
||||||
|> expressionExitVisitor node
|
|> expressionExitVisitor node
|
||||||
|
|
||||||
|
@ -5862,16 +5862,19 @@ visitDeclarationsAndExpressions declarations rules =
|
|||||||
|
|
||||||
visitDeclarationAndExpressions : Node Declaration -> JsArray RuleModuleVisitor -> JsArray RuleModuleVisitor
|
visitDeclarationAndExpressions : Node Declaration -> JsArray RuleModuleVisitor -> JsArray RuleModuleVisitor
|
||||||
visitDeclarationAndExpressions declaration rules =
|
visitDeclarationAndExpressions declaration rules =
|
||||||
rules
|
let
|
||||||
|> mutatingMap (\acc -> runVisitor .declarationVisitorOnEnter declaration acc)
|
updatedRules : JsArray RuleModuleVisitor
|
||||||
|> (\updatedRules ->
|
updatedRules =
|
||||||
case Node.value declaration of
|
rules
|
||||||
Declaration.FunctionDeclaration function ->
|
|> mutatingMap (\acc -> runVisitor .declarationVisitorOnEnter declaration acc)
|
||||||
visitExpression (Node.value function.declaration |> .expression) updatedRules
|
in
|
||||||
|
(case Node.value declaration of
|
||||||
|
Declaration.FunctionDeclaration function ->
|
||||||
|
visitExpression (Node.value function.declaration |> .expression) updatedRules
|
||||||
|
|
||||||
_ ->
|
_ ->
|
||||||
updatedRules
|
updatedRules
|
||||||
)
|
)
|
||||||
|> mutatingMap (\acc -> runVisitor .declarationVisitorOnExit declaration acc)
|
|> mutatingMap (\acc -> runVisitor .declarationVisitorOnExit declaration acc)
|
||||||
|
|
||||||
|
|
||||||
@ -5879,38 +5882,44 @@ visitExpression : Node Expression -> JsArray RuleModuleVisitor -> JsArray RuleMo
|
|||||||
visitExpression node rules =
|
visitExpression node rules =
|
||||||
case Node.value node of
|
case Node.value node of
|
||||||
Expression.LetExpression letBlock ->
|
Expression.LetExpression letBlock ->
|
||||||
rules
|
let
|
||||||
|> mutatingMap (\acc -> runVisitor .expressionVisitorOnEnter node acc)
|
updatedRules : JsArray RuleModuleVisitor
|
||||||
|> (\updatedRules ->
|
updatedRules =
|
||||||
List.foldl
|
rules
|
||||||
(visitLetDeclaration (Node (Node.range node) letBlock))
|
|> mutatingMap (\acc -> runVisitor .expressionVisitorOnEnter node acc)
|
||||||
updatedRules
|
in
|
||||||
letBlock.declarations
|
List.foldl
|
||||||
)
|
(visitLetDeclaration (Node (Node.range node) letBlock))
|
||||||
|
updatedRules
|
||||||
|
letBlock.declarations
|
||||||
|> visitExpression letBlock.expression
|
|> visitExpression letBlock.expression
|
||||||
|> mutatingMap (\acc -> runVisitor .expressionVisitorOnExit node acc)
|
|> mutatingMap (\acc -> runVisitor .expressionVisitorOnExit node acc)
|
||||||
|
|
||||||
Expression.CaseExpression caseBlock ->
|
Expression.CaseExpression caseBlock ->
|
||||||
rules
|
let
|
||||||
|> mutatingMap (\acc -> runVisitor .expressionVisitorOnEnter node acc)
|
updatedRules : JsArray RuleModuleVisitor
|
||||||
|> visitExpression caseBlock.expression
|
updatedRules =
|
||||||
|> (\updatedRules ->
|
rules
|
||||||
List.foldl
|
|> mutatingMap (\acc -> runVisitor .expressionVisitorOnEnter node acc)
|
||||||
(\case_ acc -> visitCaseBranch (Node (Node.range node) caseBlock) case_ acc)
|
|> visitExpression caseBlock.expression
|
||||||
updatedRules
|
in
|
||||||
caseBlock.cases
|
List.foldl
|
||||||
)
|
(\case_ acc -> visitCaseBranch (Node (Node.range node) caseBlock) case_ acc)
|
||||||
|
updatedRules
|
||||||
|
caseBlock.cases
|
||||||
|> mutatingMap (\acc -> runVisitor .expressionVisitorOnExit node acc)
|
|> mutatingMap (\acc -> runVisitor .expressionVisitorOnExit node acc)
|
||||||
|
|
||||||
_ ->
|
_ ->
|
||||||
rules
|
let
|
||||||
|> mutatingMap (\acc -> runVisitor .expressionVisitorOnEnter node acc)
|
updatedRules : JsArray RuleModuleVisitor
|
||||||
|> (\updatedRules ->
|
updatedRules =
|
||||||
List.foldl
|
rules
|
||||||
visitExpression
|
|> mutatingMap (\acc -> runVisitor .expressionVisitorOnEnter node acc)
|
||||||
updatedRules
|
in
|
||||||
(expressionChildren node)
|
List.foldl
|
||||||
)
|
visitExpression
|
||||||
|
updatedRules
|
||||||
|
(expressionChildren node)
|
||||||
|> mutatingMap (\acc -> runVisitor .expressionVisitorOnExit node acc)
|
|> mutatingMap (\acc -> runVisitor .expressionVisitorOnExit node acc)
|
||||||
|
|
||||||
|
|
||||||
|
@ -1361,6 +1361,7 @@ tests : Test
|
|||||||
tests = Test.describe "thing" B.helper
|
tests = Test.describe "thing" B.helper
|
||||||
""", """
|
""", """
|
||||||
module B exposing (helper)
|
module B exposing (helper)
|
||||||
|
{-| Module docs -}
|
||||||
{-| @ignore-helper -}
|
{-| @ignore-helper -}
|
||||||
helper = 1
|
helper = 1
|
||||||
""" ]
|
""" ]
|
||||||
|
@ -156,6 +156,7 @@ b = 2"""
|
|||||||
, test "should report unused top-level variables with documentation attached" <|
|
, test "should report unused top-level variables with documentation attached" <|
|
||||||
\() ->
|
\() ->
|
||||||
"""module SomeModule exposing (b)
|
"""module SomeModule exposing (b)
|
||||||
|
{-| Module docs -}
|
||||||
{-| Documentation
|
{-| Documentation
|
||||||
-}
|
-}
|
||||||
unusedVar = 1
|
unusedVar = 1
|
||||||
@ -168,11 +169,13 @@ b = 2"""
|
|||||||
, under = "unusedVar"
|
, under = "unusedVar"
|
||||||
}
|
}
|
||||||
|> Review.Test.whenFixed """module SomeModule exposing (b)
|
|> Review.Test.whenFixed """module SomeModule exposing (b)
|
||||||
|
{-| Module docs -}
|
||||||
b = 2"""
|
b = 2"""
|
||||||
]
|
]
|
||||||
, test "should report unused top-level variables with documentation attached even if they are annotated" <|
|
, test "should report unused top-level variables with documentation attached even if they are annotated" <|
|
||||||
\() ->
|
\() ->
|
||||||
"""module SomeModule exposing (b)
|
"""module SomeModule exposing (b)
|
||||||
|
{-| Module docs -}
|
||||||
{-| Documentation
|
{-| Documentation
|
||||||
-}
|
-}
|
||||||
unusedVar : Int
|
unusedVar : Int
|
||||||
@ -185,8 +188,9 @@ b = 2"""
|
|||||||
, details = details
|
, details = details
|
||||||
, under = "unusedVar"
|
, 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)
|
|> Review.Test.whenFixed """module SomeModule exposing (b)
|
||||||
|
{-| Module docs -}
|
||||||
b = 2"""
|
b = 2"""
|
||||||
]
|
]
|
||||||
, test "should not report unused top-level variables if everything is exposed (functions)" <|
|
, test "should not report unused top-level variables if everything is exposed (functions)" <|
|
||||||
@ -642,7 +646,7 @@ topLevelVariablesUsedInLetInTests =
|
|||||||
"""module SomeModule exposing (a)
|
"""module SomeModule exposing (a)
|
||||||
b = 1
|
b = 1
|
||||||
a = let c = 1
|
a = let c = 1
|
||||||
in b + c"""
|
in b + c"""
|
||||||
|> Review.Test.run rule
|
|> Review.Test.run rule
|
||||||
|> Review.Test.expectNoErrors
|
|> Review.Test.expectNoErrors
|
||||||
, test "should not report top-level variables used inside let declarations" <|
|
, test "should not report top-level variables used inside let declarations" <|
|
||||||
@ -650,21 +654,25 @@ in b + c"""
|
|||||||
"""module SomeModule exposing (a)
|
"""module SomeModule exposing (a)
|
||||||
b = 1
|
b = 1
|
||||||
a = let c = b
|
a = let c = b
|
||||||
in c"""
|
in c
|
||||||
|
"""
|
||||||
|> Review.Test.run rule
|
|> Review.Test.run rule
|
||||||
|> Review.Test.expectNoErrors
|
|> Review.Test.expectNoErrors
|
||||||
, test "should not report top-level variables used in nested lets" <|
|
, test "should not report top-level variables used in nested lets" <|
|
||||||
\() ->
|
\() ->
|
||||||
"""module SomeModule exposing (a)
|
"""module SomeModule exposing (a)
|
||||||
b = 1
|
b = 1
|
||||||
a = let
|
a =
|
||||||
c = b
|
let
|
||||||
d = let
|
c = b
|
||||||
e = 1
|
d =
|
||||||
in
|
let
|
||||||
b + c + e
|
e = 1
|
||||||
in
|
in
|
||||||
d"""
|
b + c + e
|
||||||
|
in
|
||||||
|
d
|
||||||
|
"""
|
||||||
|> Review.Test.run rule
|
|> Review.Test.run rule
|
||||||
|> Review.Test.expectNoErrors
|
|> Review.Test.expectNoErrors
|
||||||
]
|
]
|
||||||
@ -2016,6 +2024,7 @@ a = 1"""
|
|||||||
, test "should report unused custom type declarations with documentation" <|
|
, test "should report unused custom type declarations with documentation" <|
|
||||||
\() ->
|
\() ->
|
||||||
"""module SomeModule exposing (a)
|
"""module SomeModule exposing (a)
|
||||||
|
{-| Module docs -}
|
||||||
{-| Documentation -}
|
{-| Documentation -}
|
||||||
type UnusedType = B | C
|
type UnusedType = B | C
|
||||||
a = 1"""
|
a = 1"""
|
||||||
@ -2027,6 +2036,7 @@ a = 1"""
|
|||||||
, under = "UnusedType"
|
, under = "UnusedType"
|
||||||
}
|
}
|
||||||
|> Review.Test.whenFixed """module SomeModule exposing (a)
|
|> Review.Test.whenFixed """module SomeModule exposing (a)
|
||||||
|
{-| Module docs -}
|
||||||
a = 1"""
|
a = 1"""
|
||||||
]
|
]
|
||||||
, test "should report unused custom type declaration even when it references itself" <|
|
, 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" <|
|
, test "should report unused type aliases declarations with documentation" <|
|
||||||
\() ->
|
\() ->
|
||||||
"""module SomeModule exposing (a)
|
"""module SomeModule exposing (a)
|
||||||
|
{-| Module docs -}
|
||||||
{-| Documentation -}
|
{-| Documentation -}
|
||||||
type alias UnusedType = { a : B }
|
type alias UnusedType = { a : B }
|
||||||
a = 1"""
|
a = 1"""
|
||||||
@ -2100,6 +2111,7 @@ a = 1"""
|
|||||||
, under = "UnusedType"
|
, under = "UnusedType"
|
||||||
}
|
}
|
||||||
|> Review.Test.whenFixed """module SomeModule exposing (a)
|
|> Review.Test.whenFixed """module SomeModule exposing (a)
|
||||||
|
{-| Module docs -}
|
||||||
a = 1"""
|
a = 1"""
|
||||||
]
|
]
|
||||||
, test "should not report type alias used in a signature" <|
|
, test "should not report type alias used in a signature" <|
|
||||||
|
@ -143,7 +143,7 @@ Hint: Maybe you forgot to add the module definition at the top, like:
|
|||||||
, test "when there are multiple files" <|
|
, test "when there are multiple files" <|
|
||||||
\() ->
|
\() ->
|
||||||
[ "module MyModule exposing (.."
|
[ "module MyModule exposing (.."
|
||||||
, "module MyOtherModule exposing (..)"
|
, "module MyOtherModule exposing (..)\na = 1"
|
||||||
]
|
]
|
||||||
|> Review.Test.runOnModules testRuleReportsLiterals
|
|> Review.Test.runOnModules testRuleReportsLiterals
|
||||||
|> Review.Test.expectNoErrors
|
|> Review.Test.expectNoErrors
|
||||||
|
@ -274,10 +274,19 @@ shiftRange : ( ESN.Node String, Int ) -> { node : ESN.Node String } -> { a | nod
|
|||||||
shiftRange input _ _ =
|
shiftRange input _ _ =
|
||||||
let
|
let
|
||||||
asList : ( ESN.Node, Int ) -> List ESN.Node
|
asList : ( ESN.Node, Int ) -> List ESN.Node
|
||||||
asList ( node, _ ) = [ node ]
|
asList ( node, _ ) =
|
||||||
( ESN.Node range1 value1, length1 ) = input
|
[ node ]
|
||||||
[ ESN.Node range2 value2 ] = asList input
|
|
||||||
ESN.Node range3 value3 :: [] = asList input
|
( ESN.Node range value, length1 ) =
|
||||||
|
case asList input of
|
||||||
|
[ ESN.Node range2 value2 ] ->
|
||||||
|
input
|
||||||
|
|
||||||
|
ESN.Node range3 value3 :: _ ->
|
||||||
|
input
|
||||||
|
|
||||||
|
_ ->
|
||||||
|
input
|
||||||
in
|
in
|
||||||
range
|
range
|
||||||
"""
|
"""
|
||||||
@ -298,10 +307,19 @@ shiftRange : ( Node.Node String, Int ) -> { node : Node.Node String } -> { a | n
|
|||||||
shiftRange input _ _ =
|
shiftRange input _ _ =
|
||||||
let
|
let
|
||||||
asList : ( Node.Node, Int ) -> List Node.Node
|
asList : ( Node.Node, Int ) -> List Node.Node
|
||||||
asList ( node, _ ) = [ node ]
|
asList ( node, _ ) =
|
||||||
( Node.Node range1 value1, length1 ) = input
|
[ node ]
|
||||||
[ Node.Node range2 value2 ] = asList input
|
|
||||||
Node.Node range3 value3 :: [] = asList input
|
( Node.Node range value, length1 ) =
|
||||||
|
case asList input of
|
||||||
|
[ Node.Node range2 value2 ] ->
|
||||||
|
input
|
||||||
|
|
||||||
|
Node.Node range3 value3 :: _ ->
|
||||||
|
input
|
||||||
|
|
||||||
|
_ ->
|
||||||
|
input
|
||||||
in
|
in
|
||||||
range
|
range
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user