1
1
import Promise from 'bluebird'
2
2
import exec from 'execa'
3
+ import program from 'commander'
3
4
import path from 'path'
4
5
import { CLIEngine } from 'eslint'
5
6
import {
6
7
assoc ,
8
+ curry ,
7
9
endsWith ,
8
10
evolve ,
9
11
filter ,
@@ -20,25 +22,26 @@ import { getChangedLinesFromDiff } from './lib/git'
20
22
21
23
const linter = new CLIEngine ( )
22
24
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' ) )
27
25
28
26
const getChangedFiles = pipeP (
29
- ( ) => exec ( 'git' , [ 'diff' , COMMIT_RANGE , '--name-only' ] ) ,
27
+ commitRange => exec ( 'git' , [ 'diff' , commitRange , '--name-only' ] ) ,
30
28
prop ( 'stdout' ) ,
31
29
split ( '\n' ) ,
32
30
filter ( endsWith ( '.js' ) ) ,
33
31
map ( path . resolve )
34
32
)
35
33
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 ) ,
38
40
getChangedLinesFromDiff ,
39
41
objOf ( 'changedLines' ) ,
40
42
assoc ( 'filePath' , filePath )
41
- ) ( filePath )
43
+ ) ( filePath ) )
44
+
42
45
43
46
const lintChangedLines = pipe (
44
47
map ( prop ( 'filePath' ) ) ,
@@ -74,11 +77,15 @@ const reportResults = pipe(
74
77
formatter
75
78
)
76
79
77
- const run = ( ) => Promise . resolve ( )
80
+ const run = commitRange => Promise . resolve ( commitRange )
78
81
. then ( getChangedFiles )
79
- . map ( getChangedFileLineMap )
82
+ . map ( getChangedFileLineMap ( commitRange ) )
80
83
. then ( applyLinter )
81
84
. then ( reportResults )
82
85
. tap ( console . log )
83
86
84
- run ( )
87
+ program
88
+ . command ( 'lint <commit_range>' )
89
+ . action ( run )
90
+
91
+ program . parse ( process . argv )
0 commit comments