mirror of
https://github.com/jfmengels/elm-review.git
synced 2024-11-24 07:33:38 +03:00
Create formatter type
This commit is contained in:
parent
9536c1cb6f
commit
275b0b9bd0
23
src/Lint.elm
23
src/Lint.elm
@ -1,4 +1,4 @@
|
||||
module Lint exposing (lintSource, lint, visitExpression, doNothing)
|
||||
module Lint exposing (lintSource, lint, visitExpression, doNothing, countErrors)
|
||||
|
||||
{-| A linter for Elm.
|
||||
|
||||
@ -28,13 +28,16 @@ To run the rules on a source code and get a list of errors:
|
||||
|
||||
# Rule creation functions
|
||||
@docs lint, doNothing, visitExpression
|
||||
|
||||
# Internal
|
||||
@docs countErrors
|
||||
-}
|
||||
|
||||
import Ast
|
||||
import Ast.Expression exposing (Expression)
|
||||
import Ast.Statement exposing (Statement)
|
||||
import Combine
|
||||
import Lint.Types exposing (LintRule, LintError, LintImplementation, LintRuleImplementation, Direction, Visitor, Severity, Severity(..))
|
||||
import Lint.Types exposing (File, LintRule, LintError, LintImplementation, LintRuleImplementation, Direction, Visitor, Severity, Severity(..))
|
||||
import Lint.Visitor exposing (transformStatementsIntoVisitors, expressionToVisitors)
|
||||
import Regex
|
||||
|
||||
@ -152,3 +155,19 @@ context. This is used to avoid a bit of boilerplate for visitor functions whose
|
||||
doNothing : LintImplementation a context
|
||||
doNothing ctx _ =
|
||||
( [], ctx )
|
||||
|
||||
|
||||
{-| Count the number of errors of a given Severity in the list of errors.
|
||||
-}
|
||||
countErrors : Severity -> List ( File, List ( Severity, LintError ) ) -> Int
|
||||
countErrors severity errors =
|
||||
errors
|
||||
|> List.map
|
||||
(Tuple.second
|
||||
>> List.filter
|
||||
(Tuple.first
|
||||
>> (==) severity
|
||||
)
|
||||
>> List.length
|
||||
)
|
||||
|> List.sum
|
||||
|
@ -1,4 +1,17 @@
|
||||
module Lint.Types exposing (LintError, LintImplementation, Direction(..), LintRule, LintRuleImplementation, LintResult, Visitor, Severity, Severity(..))
|
||||
module Lint.Types
|
||||
exposing
|
||||
( Direction(..)
|
||||
, File
|
||||
, LintError
|
||||
, LintImplementation
|
||||
, LintResult
|
||||
, LintRule
|
||||
, LintRuleImplementation
|
||||
, Reporter
|
||||
, Severity
|
||||
, Severity(..)
|
||||
, Visitor
|
||||
)
|
||||
|
||||
{-| This module contains types that are used for writing rules.
|
||||
|
||||
@ -6,13 +19,13 @@ module Lint.Types exposing (LintError, LintImplementation, Direction(..), LintRu
|
||||
@docs LintError, Direction
|
||||
|
||||
# Configuration
|
||||
@docs LintRule, Severity
|
||||
@docs LintRule, Severity, Reporter
|
||||
|
||||
# Writing rules
|
||||
@docs LintRuleImplementation, LintImplementation
|
||||
|
||||
# Internal types
|
||||
@docs Visitor, LintResult
|
||||
@docs Visitor, LintResult, File
|
||||
-}
|
||||
|
||||
import Ast.Expression exposing (..)
|
||||
@ -142,3 +155,17 @@ type Severity
|
||||
= Disabled
|
||||
| Warning
|
||||
| Critical
|
||||
|
||||
|
||||
{-| Description of an Elm file.
|
||||
-}
|
||||
type alias File =
|
||||
{ filename : String
|
||||
, source : String
|
||||
}
|
||||
|
||||
|
||||
{-| Function that summarizes the result of the linting process.
|
||||
-}
|
||||
type alias Reporter a =
|
||||
List ( File, List ( Severity, LintError ) ) -> a
|
||||
|
Loading…
Reference in New Issue
Block a user