@@ -16,7 +16,6 @@ const getCachedDiff = (filePath: string, staged: boolean) =>
16
16
17
17
const diffCache = new Map < string , string > ( ) ;
18
18
const getDiffForFile = ( filePath : string , staged = false ) : string => {
19
- // console.log("getDiffForFile")
20
19
let diff = getCachedDiff ( filePath , staged ) ;
21
20
if ( diff === undefined ) {
22
21
const command = [
@@ -25,7 +24,7 @@ const getDiffForFile = (filePath: string, staged = false): string => {
25
24
"--diff-filter=ACM" ,
26
25
staged && "--staged" ,
27
26
"--unified=0" ,
28
- JSON . stringify ( process . env . ESLINT_PLUGIN_DIFF_COMMIT ) ?? "HEAD" ,
27
+ JSON . stringify ( process . env . ESLINT_PLUGIN_DIFF_COMMIT ?? "HEAD" ) ,
29
28
"--" ,
30
29
sanitizeFilePath ( filePath ) ,
31
30
]
@@ -40,17 +39,16 @@ const getDiffForFile = (filePath: string, staged = false): string => {
40
39
return diff ;
41
40
} ;
42
41
43
- let diffFileListCache : string [ ] ;
42
+ let diffFileListCache : string [ ] | undefined ;
44
43
const getDiffFileList = ( staged = false ) : string [ ] => {
45
- // console.log("getDiffFileList")
46
44
if ( diffFileListCache === undefined ) {
47
45
const command = [
48
46
"git" ,
49
47
"diff" ,
50
48
"--diff-filter=ACM" ,
51
49
"--name-only" ,
52
50
staged && "--staged" ,
53
- JSON . stringify ( process . env . ESLINT_PLUGIN_DIFF_COMMIT ) ?? "HEAD" ,
51
+ JSON . stringify ( process . env . ESLINT_PLUGIN_DIFF_COMMIT ?? "HEAD" ) ,
54
52
]
55
53
. filter ( Boolean )
56
54
. join ( " " ) ;
@@ -65,66 +63,29 @@ const getDiffFileList = (staged = false): string[] => {
65
63
return diffFileListCache ;
66
64
} ;
67
65
68
- let gitFileListCache : string [ ] ;
66
+ let gitFileListCache : string [ ] | undefined ;
69
67
const getGitFileList = ( ) : string [ ] => {
70
- // console.log("getGitFileList")
71
68
if ( gitFileListCache === undefined ) {
72
69
const command = [ "git" , "ls-files" ] . filter ( Boolean ) . join ( " " ) ;
73
70
74
71
gitFileListCache = child_process
75
- . execSync ( command )
76
- . toString ( )
77
- . trim ( )
78
- . split ( "\n" )
79
- . map ( ( filePath ) => path . resolve ( filePath ) ) ;
72
+ . execSync ( command )
73
+ . toString ( )
74
+ . trim ( )
75
+ . split ( "\n" )
76
+ . map ( ( filePath ) => path . resolve ( filePath ) ) ;
80
77
}
81
- // console.log({gitFileListCache},gitFileListCache.join("\n"))
82
78
return gitFileListCache ;
83
79
} ;
84
80
85
81
const getIgnorePatterns = ( staged = false ) : string [ ] => {
86
- const diffFileList = getDiffFileList ( staged ) ;
87
- const gitFileList = getGitFileList ( ) ;
88
- // console.log({diffFileList, gitFileList})
89
-
90
- const newList = gitFileList . filter ( ( x ) => ! diffFileList . includes ( x ) ) ;
91
- const willBeChecked = gitFileList . filter ( ( x ) => diffFileList . includes ( x ) ) ;
82
+ const changedFiles = getDiffFileList ( staged ) ;
92
83
93
- // throw new Error("Function not implemented.");
94
- const result = newList . map ( ( x ) =>
95
- path . join ( "/" , path . relative ( process . cwd ( ) , x ) )
96
- ) ;
84
+ const unchangedFiles = getGitFileList ( )
85
+ . filter ( ( x ) => ! changedFiles . includes ( x ) )
86
+ . map ( ( x ) => path . join ( "/" , path . relative ( process . cwd ( ) , x ) ) ) ;
97
87
98
- console . log ( "😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀" ) ;
99
- console . log ( "😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀" ) ;
100
- console . log ( "😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀" ) ;
101
- console . log ( "😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀" ) ;
102
- console . log ( "😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀" ) ;
103
- console . log ( "😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀" ) ;
104
- console . log ( "😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀" ) ;
105
- console . log ( "😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀" ) ;
106
- console . log ( "😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀" ) ;
107
- console . log ( "😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀" ) ;
108
- console . log ( "😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀" ) ;
109
- console . log ( "😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀" ) ;
110
- console . log ( "😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀" ) ;
111
- console . log ( "😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀" ) ;
112
- console . log ( "😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀" ) ;
113
- console . log ( "😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀" ) ;
114
- console . log ( "will be checked" + willBeChecked . join ( "\n" ) ) ;
115
- console . log ( "------------------" ) ;
116
- console . log ( "------------------" ) ;
117
- console . log ( "------------------" ) ;
118
- console . log ( "------------------" ) ;
119
- console . log ( "------------------" ) ;
120
- console . log ( "------------------" ) ;
121
- console . log ( "------------------" ) ;
122
- console . log ( "------------------" ) ;
123
- console . log ( "------------------" ) ;
124
- console . log ( "------------------" ) ;
125
- console . log ( "------------------" ) ;
126
- console . log ( "will be ignored" + newList . join ( "\n" ) ) ;
127
- return result ;
88
+ return unchangedFiles ;
128
89
} ;
129
90
130
91
const isHunkHeader = ( input : string ) => {
@@ -162,18 +123,12 @@ const getRangeForChangedLines = (line: string) => {
162
123
163
124
const removeNullRanges = ( r : Range | null ) : r is Range => r !== null ;
164
125
165
- const getRangesForDiff = ( diff : string ) : Range [ ] => {
166
- return diff
126
+ const getRangesForDiff = ( diff : string ) : Range [ ] =>
127
+ diff
167
128
. split ( "\n" )
168
129
. filter ( isHunkHeader )
169
130
. map ( getRangeForChangedLines )
170
131
. filter ( removeNullRanges ) ;
171
- } ;
172
132
173
- export {
174
- getDiffForFile ,
175
- getIgnorePatterns ,
176
- getRangesForDiff ,
177
- getDiffFileList ,
178
- } ;
133
+ export { getDiffForFile , getIgnorePatterns , getRangesForDiff , getDiffFileList } ;
179
134
export type { Range } ;
0 commit comments