Skip to content

Commit

Permalink
cli: process exit with status
Browse files Browse the repository at this point in the history
  • Loading branch information
grvcoelho committed Apr 13, 2018
1 parent 174843e commit e137fb4
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions src/difflint.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,26 @@ import exec from 'execa'
import path from 'path'
import { CLIEngine } from 'eslint'
import {
T,
assoc,
cond,
curry,
curryN,
endsWith,
evolve,
equals,
filter,
find,
map,
objOf,
pipe,
pipeP,
pluck,
prop,
propEq,
split,
sum,
tap,
} from 'ramda'
import { getChangedLinesFromDiff } from './lib/git'

Expand Down Expand Up @@ -70,16 +77,33 @@ const applyLinter = changedFileLineMap => pipe(
filterLinterMessages(changedFileLineMap)
)(changedFileLineMap)

const reportResults = pipe(
const logResults = pipe(
prop('results'),
formatter,
console.log
)

const getErrorCountFromReport = pipe(
prop('results'),
formatter
pluck('errorCount'),
sum
)

const exitProcess = curryN(2, n => process.exit(n))

const reportResults = pipe(
tap(logResults),
getErrorCountFromReport,
cond([
[equals(0), exitProcess(0)],
[T, exitProcess(1)],
])
)

const run = commitRange => Promise.resolve(commitRange)
.then(getChangedFiles)
.map(getChangedFileLineMap(commitRange))
.then(applyLinter)
.then(reportResults)
.tap(console.log)

export default run

0 comments on commit e137fb4

Please sign in to comment.