Format linting output

This commit is contained in:
Jeroen Engels 2017-06-16 01:23:03 +02:00
parent c20be88081
commit 688813eded
2 changed files with 22 additions and 6 deletions

View File

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

View File

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