Move LintResult from Lint.Error to TestUtil

This commit is contained in:
Jeroen Engels 2019-06-26 11:51:48 +02:00
parent b324066736
commit fbbb70749b
8 changed files with 21 additions and 21 deletions

View File

@ -11,7 +11,7 @@ If you are familiar with [ESLint](http://eslint.org/) from JavaScript, this is p
The idea is to improve your Elm source code base, after it passes compilation and [elm-format](https://github.com/avh4/elm-format) has been run on it. The idea is to improve your Elm source code base, after it passes compilation and [elm-format](https://github.com/avh4/elm-format) has been run on it.
This packages offers a few rules that you can pick and configure to improve your code base, but you can also create your own rules, to enforce rules specific to your project or team. A few cases: This packages offers a few rules that you can pick and configure to improve your code base, but you can also create your own rules, to enforce rules specific to your project or team. A few cases:
- You noticed a bad pattern in your codebase, wrote a nice module to handle the pattern better, and want to prevent your team from writing that pattern from now on. You can then write a rule to detect that pattern and have it suggest using your module instead. - You noticed a bad pattern in your codebase, wrote a nice module to handle the pattern better, and want to prevent your team from writing that pattern from now on. You can then write a rule to detect that pattern and have it suggest using your module instead. If you don't, you need to communicate this well to all your
- When using the [core HTML package](https://package.elm-lang.org/packages/elm/html/latest/), you may style your tags using the [style function](https://package.elm-lang.org/packages/elm/html/latest/Html-Attributes#style). When using [elm-css](https://package.elm-lang.org/packages/rtfeldman/elm-css), you probably want to avoid using that function (or the core HTML package altogether) and can write a rule for it. - When using the [core HTML package](https://package.elm-lang.org/packages/elm/html/latest/), you may style your tags using the [style function](https://package.elm-lang.org/packages/elm/html/latest/Html-Attributes#style). When using [elm-css](https://package.elm-lang.org/packages/rtfeldman/elm-css), you probably want to avoid using that function (or the core HTML package altogether) and can write a rule for it.
- You published a library in the Elm package registry, and notice some pitfalls that users can fall in, that all your research for a better API do not prevent. You can then publish a separate package (or even in the same package) with rules preventing those pitfalls, should the user use `elm-lint` in their project. - You published a library in the Elm package registry, and notice some pitfalls that users can fall in, that all your research for a better API do not prevent. You can then publish a separate package (or even in the same package) with rules preventing those pitfalls, should the user use `elm-lint` in their project.
- You often notice that strings in your codebase contain very common typos, or bad use of punctuation (like a missing space after `;`). - You often notice that strings in your codebase contain very common typos, or bad use of punctuation (like a missing space after `;`).

View File

@ -1,5 +1,5 @@
module Lint.Error exposing module Lint.Error exposing
( Error, LintResult ( Error
, create , create
, message, range , message, range
) )
@ -13,7 +13,7 @@ module Lint.Error exposing
# Definition # Definition
@docs Error, LintResult @docs Error
# CONSTRUCTOR # CONSTRUCTOR
@ -41,12 +41,6 @@ type Error
} }
{-| Shortcut to the result of a lint rule
-}
type alias LintResult =
Result (List String) (List Error)
-- CONSTRUCTOR -- CONSTRUCTOR

View File

@ -1,11 +1,11 @@
module DefaultPatternPositionTest exposing (all) module DefaultPatternPositionTest exposing (all)
import Elm.Syntax.Range exposing (Location, Range) import Elm.Syntax.Range exposing (Location, Range)
import Lint.Error as Error exposing (Error, LintResult) import Lint.Error as Error exposing (Error)
import Lint.Rule exposing (Rule) import Lint.Rule exposing (Rule)
import Lint.Rule.DefaultPatternPosition exposing (PatternPosition(..), rule) import Lint.Rule.DefaultPatternPosition exposing (PatternPosition(..), rule)
import Test exposing (Test, describe, test) import Test exposing (Test, describe, test)
import TestUtil import TestUtil exposing (LintResult)
testRule : PatternPosition -> String -> LintResult testRule : PatternPosition -> String -> LintResult

View File

@ -1,11 +1,11 @@
module NoDebugTest exposing (all) module NoDebugTest exposing (all)
import Elm.Syntax.Range exposing (Location, Range) import Elm.Syntax.Range exposing (Location, Range)
import Lint.Error as Error exposing (Error, LintResult) import Lint.Error as Error exposing (Error)
import Lint.Rule exposing (Rule) import Lint.Rule exposing (Rule)
import Lint.Rule.NoDebug exposing (rule) import Lint.Rule.NoDebug exposing (rule)
import Test exposing (Test, describe, test) import Test exposing (Test, describe, test)
import TestUtil import TestUtil exposing (LintResult)
testRule : String -> LintResult testRule : String -> LintResult

View File

@ -1,11 +1,11 @@
module NoExtraBooleanComparisonTest exposing (all) module NoExtraBooleanComparisonTest exposing (all)
import Elm.Syntax.Range exposing (Location, Range) import Elm.Syntax.Range exposing (Location, Range)
import Lint.Error as Error exposing (Error, LintResult) import Lint.Error as Error exposing (Error)
import Lint.Rule exposing (Rule) import Lint.Rule exposing (Rule)
import Lint.Rule.NoExtraBooleanComparison exposing (rule) import Lint.Rule.NoExtraBooleanComparison exposing (rule)
import Test exposing (Test, describe, test) import Test exposing (Test, describe, test)
import TestUtil import TestUtil exposing (LintResult)
testRule : String -> LintResult testRule : String -> LintResult

View File

@ -1,11 +1,11 @@
module NoImportingEverythingTest exposing (all) module NoImportingEverythingTest exposing (all)
import Elm.Syntax.Range exposing (Location, Range) import Elm.Syntax.Range exposing (Location, Range)
import Lint.Error as Error exposing (Error, LintResult) import Lint.Error as Error exposing (Error)
import Lint.Rule exposing (Rule) import Lint.Rule exposing (Rule)
import Lint.Rule.NoImportingEverything exposing (Configuration, rule) import Lint.Rule.NoImportingEverything exposing (Configuration, rule)
import Test exposing (Test, describe, test) import Test exposing (Test, describe, test)
import TestUtil import TestUtil exposing (LintResult)
testRule : Configuration -> String -> LintResult testRule : Configuration -> String -> LintResult

View File

@ -1,11 +1,11 @@
module NoUnusedVariablesTest exposing (all) module NoUnusedVariablesTest exposing (all)
import Elm.Syntax.Range exposing (Location, Range) import Elm.Syntax.Range exposing (Location, Range)
import Lint.Error as Error exposing (Error, LintResult) import Lint.Error as Error exposing (Error)
import Lint.Rule exposing (Rule) import Lint.Rule exposing (Rule)
import Lint.Rule.NoUnusedVariables exposing (rule) import Lint.Rule.NoUnusedVariables exposing (rule)
import Test exposing (Test, describe, test) import Test exposing (Test, describe, test)
import TestUtil import TestUtil exposing (LintResult)
testRule : String -> LintResult testRule : String -> LintResult

View File

@ -1,12 +1,18 @@
module TestUtil exposing (errorWithoutRange, expectErrors, expectErrorsWithoutRange, location, ruleTester) module TestUtil exposing (LintResult, errorWithoutRange, expectErrors, expectErrorsWithoutRange, location, ruleTester)
import Elm.Syntax.Range exposing (Range) import Elm.Syntax.Range exposing (Range)
import Expect import Expect
import Lint exposing (Severity(..), lintSource) import Lint exposing (Severity(..), lintSource)
import Lint.Error as Error exposing (Error, LintResult) import Lint.Error as Error exposing (Error)
import Lint.Rule exposing (Rule) import Lint.Rule exposing (Rule)
{-| Result of a lint rule being applied on a string containing Elm code.
-}
type alias LintResult =
Result (List String) (List Error)
ruleTester : Rule -> String -> Result (List String) (List Error) ruleTester : Rule -> String -> Result (List String) (List Error)
ruleTester rule str = ruleTester rule str =
lintSource [ ( Critical, rule ) ] str lintSource [ ( Critical, rule ) ] str