@@ -20,6 +20,7 @@ const STAGED = true;
20
20
const getPreProcessor = ( staged = false ) => {
21
21
const untrackedFileList = getUntrackedFileList ( staged ) ;
22
22
const diffFileList = getDiffFileList ( staged ) ;
23
+
23
24
return ( text : string , filename : string ) => {
24
25
const shouldBeProcessed =
25
26
process . env . VSCODE_CLI !== undefined ||
@@ -30,9 +31,29 @@ const getPreProcessor = (staged = false) => {
30
31
} ;
31
32
} ;
32
33
33
- const isLineWithinRange = ( line : number ) => ( range : Range ) => {
34
- return range . isWithinRange ( line ) ;
35
- } ;
34
+ const isLineWithinRange = ( line : number ) => ( range : Range ) =>
35
+ range . isWithinRange ( line ) ;
36
+
37
+ function getUnstagedChangesError ( filename : string ) {
38
+ // When we only want to diff staged files, but the file is partially
39
+ // staged, the ranges of the staged diff might not match the ranges of the
40
+ // unstaged diff and could cause a conflict, so we return a fatal
41
+ // error-message instead.
42
+
43
+ const fatal = true ;
44
+ const message = `${ filename } has unstaged changes. Please stage or remove the changes.` ;
45
+ const severity : Linter . Severity = 2 ;
46
+ const fatalError : Linter . LintMessage = {
47
+ fatal,
48
+ message,
49
+ severity,
50
+ column : 0 ,
51
+ line : 0 ,
52
+ ruleId : null ,
53
+ } ;
54
+
55
+ return [ fatalError ] ;
56
+ }
36
57
37
58
const getPostProcessor = ( staged = false ) => {
38
59
const untrackedFileList = getUntrackedFileList ( staged ) ;
@@ -53,44 +74,26 @@ const getPostProcessor = (staged = false) => {
53
74
}
54
75
55
76
if ( staged && ! hasCleanIndex ( filename ) ) {
56
- // When we only want to diff staged files, but the file is partially
57
- // staged, the ranges of the staged diff might not match the ranges of the
58
- // unstaged diff and could cause a conflict, so we return a fatal
59
- // error-message instead.
60
- const fatal = true ;
61
- const message = `${ filename } has unstaged changes. Please stage or remove the changes.` ;
62
- const severity : Linter . Severity = 2 ;
63
- const fatalError : Linter . LintMessage = {
64
- fatal,
65
- message,
66
- severity,
67
- column : 0 ,
68
- line : 0 ,
69
- ruleId : null ,
70
- } ;
71
-
72
- return [ fatalError ] ;
77
+ return getUnstagedChangesError ( filename ) ;
73
78
}
74
79
75
80
const rangesForDiff = getRangesForDiff ( getDiffForFile ( filename , staged ) ) ;
76
81
77
- return messages
78
- . map ( ( message ) => {
79
- const filteredMessage = message . filter ( ( { fatal, line } ) => {
80
- if ( fatal === true ) {
81
- return true ;
82
- }
82
+ return messages . flatMap ( ( message ) => {
83
+ const filteredMessage = message . filter ( ( { fatal, line } ) => {
84
+ if ( fatal === true ) {
85
+ return true ;
86
+ }
83
87
84
- const isLineWithinSomeRange = rangesForDiff . some (
85
- isLineWithinRange ( line )
86
- ) ;
88
+ const isLineWithinSomeRange = rangesForDiff . some (
89
+ isLineWithinRange ( line )
90
+ ) ;
87
91
88
- return isLineWithinSomeRange ;
89
- } ) ;
92
+ return isLineWithinSomeRange ;
93
+ } ) ;
90
94
91
- return filteredMessage ;
92
- } )
93
- . reduce ( ( a , b ) => a . concat ( b ) , [ ] ) ;
95
+ return filteredMessage ;
96
+ } ) ;
94
97
} ;
95
98
} ;
96
99
0 commit comments