@@ -8,7 +8,7 @@ import * as fs from "fs";
8
8
9
9
import base from "./provider/base" ;
10
10
import editorconfig from "./provider/editorconfig" ;
11
- import tslintjson from "./provider/tslintjson" ;
11
+ import tslintjson , { postProcess as tslintPostProcess } from "./provider/tslintjson" ;
12
12
13
13
export interface Options {
14
14
dryRun ?: boolean ;
@@ -21,6 +21,10 @@ export interface Options {
21
21
tsfmt : boolean ;
22
22
}
23
23
24
+ export interface PostProcess {
25
+ ( fileName : string , formattedCode : string , opts : Options , formatOptions : ts . FormatCodeOptions ) : string ;
26
+ }
27
+
24
28
export interface ResultMap {
25
29
[ fileName : string ] : Result ;
26
30
}
@@ -43,7 +47,7 @@ export function processFiles(files: string[], opts: Options): Promise<ResultMap>
43
47
let result : Result = {
44
48
fileName : fileName ,
45
49
options : null ,
46
- message : `${ fileName } is not exists . process abort.` ,
50
+ message : `${ fileName } does not exist . process abort.\n ` ,
47
51
error : true ,
48
52
src : "" ,
49
53
dest : ""
@@ -85,6 +89,7 @@ export function processString(fileName: string, content: string, opts: Options):
85
89
86
90
let formatOptions = createDefaultFormatCodeOptions ( ) ;
87
91
let optGenPromises : ( ts . FormatCodeOptions | Promise < ts . FormatCodeOptions > ) [ ] = [ ] ;
92
+ let postProcesses : PostProcess [ ] = [ ] ;
88
93
if ( opts . tsfmt ) {
89
94
optGenPromises . push ( base ( fileName , opts , formatOptions ) ) ;
90
95
}
@@ -93,6 +98,7 @@ export function processString(fileName: string, content: string, opts: Options):
93
98
}
94
99
if ( opts . tslint ) {
95
100
optGenPromises . push ( tslintjson ( fileName , opts , formatOptions ) ) ;
101
+ postProcesses . push ( tslintPostProcess ) ;
96
102
}
97
103
98
104
return Promise
@@ -104,18 +110,22 @@ export function processString(fileName: string, content: string, opts: Options):
104
110
formattedCode += "\n" ;
105
111
}
106
112
113
+ postProcesses . forEach ( postProcess => {
114
+ formattedCode = postProcess ( fileName , formattedCode , opts , formatOptions ) || formattedCode ;
115
+ } ) ;
116
+
107
117
// TODO replace newline code. NewLineCharacter params affect to only "new" newline. maybe.
108
118
let message : string ;
109
119
let error = false ;
110
120
if ( opts && opts . verify ) {
111
121
if ( content !== formattedCode ) {
112
- message = `${ fileName } is not formatted` ;
122
+ message = `${ fileName } is not formatted\n ` ;
113
123
error = true ;
114
124
}
115
125
} else if ( opts && opts . replace ) {
116
126
if ( content !== formattedCode ) {
117
127
fs . writeFileSync ( fileName , formattedCode ) ;
118
- message = `replaced ${ fileName } ` ;
128
+ message = `replaced ${ fileName } \n ` ;
119
129
}
120
130
} else if ( opts && ! opts . dryRun ) {
121
131
message = formattedCode ;
0 commit comments