mirror of
https://github.com/jfmengels/elm-review.git
synced 2024-12-24 02:02:29 +03:00
Rename Lint.Test's "ruleTester" to "run"
This commit is contained in:
parent
1f7e5e08f8
commit
9473c123bb
@ -1,4 +1,4 @@
|
||||
module Lint.Test exposing (LintResult, errorWithoutRange, expectErrors, expectErrorsWithoutRange, location, ruleTester)
|
||||
module Lint.Test exposing (LintResult, errorWithoutRange, expectErrors, expectErrorsWithoutRange, location, run)
|
||||
|
||||
{-| Module that helps you test your linting rules, using [`elm-test`](https://package.elm-lang.org/packages/elm-explorations/test/latest).
|
||||
|
||||
@ -22,8 +22,33 @@ type alias LintResult =
|
||||
Result (List String) (List Error)
|
||||
|
||||
|
||||
ruleTester : Rule -> String -> Result (List String) (List Error)
|
||||
ruleTester rule str =
|
||||
{-| Run a `Rule` on a string and get the errors reported by it. If the string is
|
||||
not valid Elm code, this will return a `Result` of type `Err`.
|
||||
|
||||
Note that to be valid, a code needs to start with a module definition followed by
|
||||
a line break like `module A exposing (..)\n`.
|
||||
|
||||
import Lint.Test exposing (LintResult)
|
||||
import Test
|
||||
|
||||
testRule : String -> LintResult
|
||||
testRule string =
|
||||
"module A exposing (..)\n\n"
|
||||
++ string
|
||||
|> Lint.Test.run rule
|
||||
|
||||
tests : List Test
|
||||
tests =
|
||||
[ test "should not report normal function calls" <|
|
||||
\() ->
|
||||
testRule "a = Debug.log"
|
||||
|> Lint.Test.expectErrors
|
||||
[ error (Lint.Test.location ( 3, 5 ) ( 3, 14 )) ]
|
||||
]
|
||||
|
||||
-}
|
||||
run : Rule -> String -> Result (List String) (List Error)
|
||||
run rule str =
|
||||
lintSource [ ( Critical, rule ) ] str
|
||||
|> Result.map (List.map (\( severity, { message, range } ) -> Rule.error message range))
|
||||
|
||||
|
@ -9,7 +9,7 @@ import Test exposing (Test, describe, test)
|
||||
|
||||
testRule : PatternPosition -> String -> LintResult
|
||||
testRule patternPosition =
|
||||
Lint.Test.ruleTester (rule patternPosition)
|
||||
Lint.Test.run (rule patternPosition)
|
||||
|
||||
|
||||
error : String -> Error
|
||||
|
@ -11,7 +11,7 @@ testRule : String -> LintResult
|
||||
testRule string =
|
||||
"module A exposing (..)\n\n"
|
||||
++ string
|
||||
|> Lint.Test.ruleTester rule
|
||||
|> Lint.Test.run rule
|
||||
|
||||
|
||||
error : Range -> Error
|
||||
|
@ -11,7 +11,7 @@ testRule : String -> LintResult
|
||||
testRule string =
|
||||
"module A exposing (..)\n\n"
|
||||
++ string
|
||||
|> Lint.Test.ruleTester rule
|
||||
|> Lint.Test.run rule
|
||||
|
||||
|
||||
tests : List Test
|
||||
|
@ -9,7 +9,7 @@ import Test exposing (Test, describe, test)
|
||||
|
||||
testRule : Configuration -> String -> LintResult
|
||||
testRule options =
|
||||
Lint.Test.ruleTester (rule options)
|
||||
Lint.Test.run (rule options)
|
||||
|
||||
|
||||
error : String -> Error
|
||||
|
@ -9,7 +9,7 @@ import Test exposing (Test, describe, test)
|
||||
|
||||
testRule : String -> LintResult
|
||||
testRule =
|
||||
Lint.Test.ruleTester rule
|
||||
Lint.Test.run rule
|
||||
|
||||
|
||||
tests : List Test
|
||||
|
Loading…
Reference in New Issue
Block a user