Skip to content

Commit 1076678

Browse files
committed
cli: add commander and program commands
1 parent d110c10 commit 1076678

File tree

3 files changed

+28
-15
lines changed

3 files changed

+28
-15
lines changed

package-lock.json

Lines changed: 9 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
},
3838
"dependencies": {
3939
"bluebird": "^3.5.1",
40+
"commander": "^2.15.1",
4041
"execa": "^0.10.0",
4142
"ramda": "^0.25.0"
4243
},

src/index.js

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import Promise from 'bluebird'
22
import exec from 'execa'
3+
import program from 'commander'
34
import path from 'path'
45
import { CLIEngine } from 'eslint'
56
import {
67
assoc,
8+
curry,
79
endsWith,
810
evolve,
911
filter,
@@ -20,25 +22,26 @@ import { getChangedLinesFromDiff } from './lib/git'
2022

2123
const linter = new CLIEngine()
2224
const formatter = linter.getFormatter()
23-
const COMMIT_RANGE = 'HEAD^..HEAD'
24-
25-
const getDiff = filename => exec('git', ['diff', COMMIT_RANGE, filename])
26-
.then(prop('stdout'))
2725

2826
const getChangedFiles = pipeP(
29-
() => exec('git', ['diff', COMMIT_RANGE, '--name-only']),
27+
commitRange => exec('git', ['diff', commitRange, '--name-only']),
3028
prop('stdout'),
3129
split('\n'),
3230
filter(endsWith('.js')),
3331
map(path.resolve)
3432
)
3533

36-
const getChangedFileLineMap = filePath => pipeP(
37-
getDiff,
34+
const getDiff = curry((commitRange, filename) =>
35+
exec('git', ['diff', commitRange, filename])
36+
.then(prop('stdout')))
37+
38+
const getChangedFileLineMap = curry((commitRange, filePath) => pipeP(
39+
getDiff(commitRange),
3840
getChangedLinesFromDiff,
3941
objOf('changedLines'),
4042
assoc('filePath', filePath)
41-
)(filePath)
43+
)(filePath))
44+
4245

4346
const lintChangedLines = pipe(
4447
map(prop('filePath')),
@@ -74,11 +77,15 @@ const reportResults = pipe(
7477
formatter
7578
)
7679

77-
const run = () => Promise.resolve()
80+
const run = commitRange => Promise.resolve(commitRange)
7881
.then(getChangedFiles)
79-
.map(getChangedFileLineMap)
82+
.map(getChangedFileLineMap(commitRange))
8083
.then(applyLinter)
8184
.then(reportResults)
8285
.tap(console.log)
8386

84-
run()
87+
program
88+
.command('lint <commit_range>')
89+
.action(run)
90+
91+
program.parse(process.argv)

0 commit comments

Comments
 (0)