1
1
import * as ts from "typescript" ;
2
2
import formatter from "./formatter" ;
3
- import { createDefaultFormatCodeOptions , parseJSON } from "./utils" ;
3
+ import { createDefaultFormatCodeSettings , parseJSON } from "./utils" ;
4
4
5
5
export { parseJSON } ;
6
6
@@ -24,11 +24,11 @@ export interface Options {
24
24
}
25
25
26
26
export interface OptionModifier {
27
- ( fileName : string , opts : Options , formatOptions : ts . FormatCodeOptions ) : ts . FormatCodeOptions | Promise < ts . FormatCodeOptions > ;
27
+ ( fileName : string , opts : Options , formatSettings : ts . FormatCodeSettings ) : ts . FormatCodeSettings | Promise < ts . FormatCodeSettings > ;
28
28
}
29
29
30
30
export interface PostProcessor {
31
- ( fileName : string , formattedCode : string , opts : Options , formatOptions : ts . FormatCodeOptions ) : string | Promise < string > ;
31
+ ( fileName : string , formattedCode : string , opts : Options , formatSettings : ts . FormatCodeSettings ) : string | Promise < string > ;
32
32
}
33
33
34
34
class Processor {
@@ -39,34 +39,34 @@ class Processor {
39
39
this . optionModifiers . push ( modifier ) ;
40
40
}
41
41
42
- processFormatCodeOptions ( fileName : string , opts : Options , formatOptions : ts . FormatCodeOptions ) : Promise < ts . FormatCodeOptions > {
42
+ processFormatCodeOptions ( fileName : string , opts : Options , formatSettings : ts . FormatCodeSettings ) : Promise < ts . FormatCodeSettings > {
43
43
let optionModifiers = [ ...this . optionModifiers ] ;
44
44
45
- let next = ( formatOptions : ts . FormatCodeOptions ) : Promise < ts . FormatCodeOptions > => {
45
+ let next = ( formatSettings : ts . FormatCodeSettings ) : Promise < ts . FormatCodeSettings > => {
46
46
if ( optionModifiers . length === 0 ) {
47
- return Promise . resolve ( formatOptions ) ;
47
+ return Promise . resolve ( formatSettings ) ;
48
48
}
49
- let modifier = optionModifiers . shift ( ) ! ;
50
- let ret = modifier ( fileName , opts , formatOptions ) ;
51
- return Promise . resolve ( ret ) . then ( formatOptions => next ( formatOptions ) ) ;
49
+ let modifier = optionModifiers . shift ( ) ! ;
50
+ let ret = modifier ( fileName , opts , formatSettings ) ;
51
+ return Promise . resolve ( ret ) . then ( formatSettings => next ( formatSettings ) ) ;
52
52
} ;
53
53
54
- return next ( formatOptions ) ;
54
+ return next ( formatSettings ) ;
55
55
}
56
56
57
57
addPostProcess ( postProcessor : PostProcessor ) {
58
58
this . postProcessors . push ( postProcessor ) ;
59
59
}
60
60
61
- postProcess ( fileName : string , formattedCode : string , opts : Options , formatOptions : ts . FormatCodeOptions ) : Promise < string > {
61
+ postProcess ( fileName : string , formattedCode : string , opts : Options , formatSettings : ts . FormatCodeSettings ) : Promise < string > {
62
62
let postProcessors = [ ...this . postProcessors ] ;
63
63
64
64
let next = ( formattedCode : string ) : Promise < string > => {
65
65
if ( postProcessors . length === 0 ) {
66
66
return Promise . resolve ( formattedCode ) ;
67
67
}
68
- let processor = postProcessors . shift ( ) ! ;
69
- let ret = processor ( fileName , formattedCode , opts , formatOptions ) ;
68
+ let processor = postProcessors . shift ( ) ! ;
69
+ let ret = processor ( fileName , formattedCode , opts , formatSettings ) ;
70
70
return Promise . resolve ( ret ) . then ( formattedCode => next ( formattedCode ) ) ;
71
71
} ;
72
72
@@ -80,7 +80,7 @@ export interface ResultMap {
80
80
81
81
export interface Result {
82
82
fileName : string ;
83
- options : ts . FormatCodeOptions | null ;
83
+ settings : ts . FormatCodeSettings | null ;
84
84
message : string ;
85
85
error : boolean ;
86
86
src : string ;
@@ -94,7 +94,7 @@ export function processFiles(files: string[], opts: Options): Promise<ResultMap>
94
94
if ( ! fs . existsSync ( fileName ) ) {
95
95
let result : Result = {
96
96
fileName : fileName ,
97
- options : null ,
97
+ settings : null ,
98
98
message : `${ fileName } does not exist. process abort.\n` ,
99
99
error : true ,
100
100
src : "" ,
@@ -148,19 +148,19 @@ export function processString(fileName: string, content: string, opts: Options):
148
148
processor . addOptionModify ( tslintjson ) ;
149
149
processor . addPostProcess ( tslintPostProcess ) ;
150
150
}
151
- processor . addPostProcess ( ( _fileName : string , formattedCode : string , _opts : Options , formatOptions : ts . FormatCodeOptions ) => {
151
+ processor . addPostProcess ( ( _fileName : string , formattedCode : string , _opts : Options , formatSettings : ts . FormatCodeSettings ) => {
152
152
// replace newline code. maybe NewLineCharacter params affect to only "new" newline by language service.
153
- formattedCode = formattedCode . replace ( / \r ? \n / g, formatOptions . NewLineCharacter ) ;
153
+ formattedCode = formattedCode . replace ( / \r ? \n / g, formatSettings . newLineCharacter || "\n" ) ;
154
154
return Promise . resolve ( formattedCode ) ;
155
155
} ) ;
156
156
157
- let formatOptions = createDefaultFormatCodeOptions ( ) ;
158
- return processor . processFormatCodeOptions ( fileName , opts , formatOptions )
159
- . then ( formatOptions => {
160
- let formattedCode = formatter ( fileName , content , formatOptions ) ;
157
+ let formatSettings = createDefaultFormatCodeSettings ( ) ;
158
+ return processor . processFormatCodeOptions ( fileName , opts , formatSettings )
159
+ . then ( formatSettings => {
160
+ let formattedCode = formatter ( fileName , content , formatSettings ) ;
161
161
162
162
// apply post process logic
163
- return processor . postProcess ( fileName , formattedCode , opts , formatOptions ) ;
163
+ return processor . postProcess ( fileName , formattedCode , opts , formatSettings ) ;
164
164
165
165
} ) . then ( formattedCode => {
166
166
let message = "" ;
@@ -181,7 +181,7 @@ export function processString(fileName: string, content: string, opts: Options):
181
181
182
182
let result : Result = {
183
183
fileName : fileName ,
184
- options : formatOptions ,
184
+ settings : formatSettings ,
185
185
message : message ,
186
186
error : error ,
187
187
src : content ,
0 commit comments