mirror of
https://github.com/jfmengels/elm-review.git
synced 2024-11-23 14:55:35 +03:00
Fix Review.Test not working correctly with multilines
This commit is contained in:
parent
d2c37dd489
commit
d0bd0579f3
@ -911,7 +911,7 @@ getCodeAtLocationInSourceCode sourceCode =
|
||||
lastLine : Maybe String
|
||||
lastLine =
|
||||
Array.get (end.row - 1) lines
|
||||
|> Maybe.map (String.dropRight end.column)
|
||||
|> Maybe.map (String.left end.column)
|
||||
in
|
||||
[ [ firstLine ]
|
||||
, Array.slice start.row (end.row - 1) lines
|
||||
|
43
tests/MiscRules/NoBooleanCase.elm
Normal file
43
tests/MiscRules/NoBooleanCase.elm
Normal file
@ -0,0 +1,43 @@
|
||||
module MiscRules.NoBooleanCase exposing (rule)
|
||||
|
||||
import Elm.Syntax.Expression as Expression exposing (Expression)
|
||||
import Elm.Syntax.Node as Node exposing (Node)
|
||||
import Elm.Syntax.Pattern as Pattern
|
||||
import Elm.Syntax.Range exposing (Range)
|
||||
import Review.Rule as Rule exposing (Error, Rule)
|
||||
|
||||
|
||||
rule : Rule
|
||||
rule =
|
||||
Rule.newModuleRuleSchema "NoBooleanCase" ()
|
||||
|> Rule.withSimpleExpressionVisitor expressionVisitor
|
||||
|> Rule.fromModuleRuleSchema
|
||||
|
||||
|
||||
expressionVisitor : Node Expression -> List (Error {})
|
||||
expressionVisitor (Node.Node range expression) =
|
||||
case expression of
|
||||
Expression.CaseExpression caseBlock ->
|
||||
errorsForCaseBlock range caseBlock
|
||||
|
||||
_ ->
|
||||
[]
|
||||
|
||||
|
||||
errorsForCaseBlock : Range -> Expression.CaseBlock -> List (Error {})
|
||||
errorsForCaseBlock ({ end } as range) { expression, cases } =
|
||||
case cases of
|
||||
[ ( Node.Node _ (Pattern.NamedPattern { moduleName, name } []), _ ), _ ] ->
|
||||
if moduleName == [] && (name == "True" || name == "False") then
|
||||
[ Rule.error
|
||||
{ message = "Matching boolean values in a case .. of expression"
|
||||
, details = [ "It's quite silly" ]
|
||||
}
|
||||
range
|
||||
]
|
||||
|
||||
else
|
||||
[]
|
||||
|
||||
_ ->
|
||||
[]
|
31
tests/MiscRules/NoBooleanCaseTest.elm
Normal file
31
tests/MiscRules/NoBooleanCaseTest.elm
Normal file
@ -0,0 +1,31 @@
|
||||
module MiscRules.NoBooleanCaseTest exposing (all)
|
||||
|
||||
import MiscRules.NoBooleanCase as NoBooleanCase
|
||||
import Review.Test
|
||||
import Test exposing (Test, describe, test)
|
||||
|
||||
|
||||
all : Test
|
||||
all =
|
||||
describe "noBooleanCase"
|
||||
[ test "Simple one" <|
|
||||
\_ ->
|
||||
"""module A exposing (..)
|
||||
a =
|
||||
case expr of
|
||||
True -> True
|
||||
False -> False
|
||||
"""
|
||||
|> Review.Test.run NoBooleanCase.rule
|
||||
|> Review.Test.expectErrors
|
||||
[ Review.Test.error
|
||||
{ message = "Matching boolean values in a case .. of expression"
|
||||
, details =
|
||||
[ "It's quite silly"
|
||||
]
|
||||
, under = """case expr of
|
||||
True -> True
|
||||
False -> False"""
|
||||
}
|
||||
]
|
||||
]
|
@ -555,7 +555,7 @@ import Foo
|
||||
[ Review.Test.error
|
||||
{ message = "Imported type `C` is not used"
|
||||
, details = details
|
||||
, under = "C\n "
|
||||
, under = "C\n ,"
|
||||
}
|
||||
|> Review.Test.whenFixed """module SomeModule exposing (d)
|
||||
import Foo
|
||||
|
Loading…
Reference in New Issue
Block a user