1
1
import * as child_process from "child_process" ;
2
- import * as path from "path" ;
2
+ import { resolve } from "path" ;
3
3
import { Range } from "./Range" ;
4
4
5
5
const COMMAND = "git" ;
6
6
7
- const sanitizeFilePath = ( filePath : string ) =>
8
- JSON . stringify ( path . resolve ( filePath ) ) ;
9
-
10
7
const getDiffForFile = ( filePath : string , staged = false ) : string => {
11
8
const args = [
12
9
"diff" ,
@@ -16,9 +13,9 @@ const getDiffForFile = (filePath: string, staged = false): string => {
16
13
"--relative" ,
17
14
staged && "--staged" ,
18
15
"--unified=0" ,
19
- JSON . stringify ( process . env . ESLINT_PLUGIN_DIFF_COMMIT ?? "HEAD" ) ,
16
+ process . env . ESLINT_PLUGIN_DIFF_COMMIT ?? "HEAD" ,
20
17
"--" ,
21
- sanitizeFilePath ( filePath ) ,
18
+ resolve ( filePath ) ,
22
19
] . reduce < string [ ] > (
23
20
( acc , cur ) => ( typeof cur === "string" ? [ ...acc , cur ] : acc ) ,
24
21
[ ]
@@ -36,15 +33,15 @@ const getDiffFileList = (): string[] => {
36
33
"--name-only" ,
37
34
"--relative" ,
38
35
"--staged" ,
39
- JSON . stringify ( process . env . ESLINT_PLUGIN_DIFF_COMMIT ?? "HEAD" ) ,
36
+ process . env . ESLINT_PLUGIN_DIFF_COMMIT ?? "HEAD" ,
40
37
] ;
41
38
42
39
return child_process
43
40
. execFileSync ( COMMAND , args )
44
41
. toString ( )
45
42
. trim ( )
46
43
. split ( "\n" )
47
- . map ( ( filePath ) => path . resolve ( filePath ) ) ;
44
+ . map ( ( filePath ) => resolve ( filePath ) ) ;
48
45
} ;
49
46
50
47
const hasCleanIndex = ( filePath : string ) : boolean => {
@@ -54,7 +51,7 @@ const hasCleanIndex = (filePath: string): boolean => {
54
51
"--relative" ,
55
52
"--unified=0" ,
56
53
"--" ,
57
- sanitizeFilePath ( filePath ) ,
54
+ resolve ( filePath ) ,
58
55
] ;
59
56
60
57
let result = true ;
@@ -79,7 +76,7 @@ const getUntrackedFileList = (staged = false): string[] => {
79
76
. toString ( )
80
77
. trim ( )
81
78
. split ( "\n" )
82
- . map ( ( filePath ) => path . resolve ( filePath ) ) ;
79
+ . map ( ( filePath ) => resolve ( filePath ) ) ;
83
80
84
81
return untrackedFileListCache ;
85
82
} ;
0 commit comments