Rename Lint.Test's "ruleTester" to "run"

This commit is contained in:
Jeroen Engels 2019-06-27 21:04:41 +02:00
parent 1f7e5e08f8
commit 9473c123bb
6 changed files with 33 additions and 8 deletions

View File

@ -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))

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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