Skip to content

Commit

Permalink
Merge pull request #9 from flyingluscas/fix-error-and-warning-counts
Browse files Browse the repository at this point in the history
Count errors and warnings just for changed lines
  • Loading branch information
grvcoelho authored Jul 25, 2018
2 parents 7b4e1f0 + 15ea57a commit 16c953b
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion src/lint-diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import {
equals,
filter,
find,
length,
map,
merge,
objOf,
pipe,
pipeP,
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 16c953b

Please sign in to comment.