diff --git a/src/lint-diff.js b/src/lint-diff.js index 555a098..57a1212 100644 --- a/src/lint-diff.js +++ b/src/lint-diff.js @@ -13,7 +13,9 @@ import { equals, filter, find, + length, map, + merge, objOf, pipe, pipeP, @@ -65,9 +67,38 @@ const filterLinterMessages = changedFileLineMap => (linterOutput) => { return filterMessages(result) } + const countBySeverity = severity => + pipe( + filter(propEq('severity', severity)), + length + ) + + const countWarningMessages = countBySeverity(1) + const countErrorMessages = countBySeverity(2) + + const warningCount = (result) => { + const transform = { + warningCount: countWarningMessages(result.messages), + } + + return merge(result, transform) + } + + const errorCount = (result) => { + const transform = { + errorCount: countErrorMessages(result.messages), + } + + return merge(result, transform) + } + return pipe( prop('results'), - map(filterMessagesByFile), + map(pipe( + filterMessagesByFile, + warningCount, + errorCount + )), objOf('results') )(linterOutput) }