mirror of
https://github.com/jfmengels/elm-review.git
synced 2024-12-27 03:33:00 +03:00
Format linting output
This commit is contained in:
parent
c20be88081
commit
688813eded
@ -13,6 +13,6 @@ const app = Elm.LintApp.worker();
|
||||
|
||||
app.ports.linting.send(elmFiles);
|
||||
|
||||
app.ports.resultPort.subscribe(function(result) {
|
||||
console.log(JSON.stringify(result, null, 2));
|
||||
app.ports.resultPort.subscribe(function(report) {
|
||||
console.log(report);
|
||||
});
|
||||
|
@ -16,7 +16,7 @@ type alias File =
|
||||
port linting : (List File -> msg) -> Sub msg
|
||||
|
||||
|
||||
port resultPort : List ( File, List String ) -> Cmd msg
|
||||
port resultPort : String -> Cmd msg
|
||||
|
||||
|
||||
type alias Model =
|
||||
@ -46,9 +46,16 @@ update : Msg -> Model -> ( Model, Cmd Msg )
|
||||
update msg model =
|
||||
case msg of
|
||||
Lint files ->
|
||||
( model
|
||||
, resultPort (List.map (\file -> ( file, lint file.source )) files)
|
||||
)
|
||||
let
|
||||
lintResult =
|
||||
List.map (\file -> ( file, lint file.source )) files
|
||||
|> List.filter (Tuple.second >> List.isEmpty >> not)
|
||||
|> List.map formatReport
|
||||
|> String.join "\n\n"
|
||||
in
|
||||
( model
|
||||
, resultPort lintResult
|
||||
)
|
||||
|
||||
|
||||
subscriptions : Model -> Sub Msg
|
||||
@ -63,3 +70,12 @@ main =
|
||||
, update = update
|
||||
, subscriptions = subscriptions
|
||||
}
|
||||
|
||||
|
||||
formatReport : ( File, List String ) -> String
|
||||
formatReport ( { filename }, errors ) =
|
||||
(toString (List.length errors))
|
||||
++ " errors found in '"
|
||||
++ filename
|
||||
++ "':\n\n\t"
|
||||
++ (String.join "\n\t" errors)
|
||||
|
Loading…
Reference in New Issue
Block a user