@@ -29,7 +29,7 @@ export interface AdditionalFormatSettings {
29
29
$noConsecutiveBlankLines : boolean ;
30
30
}
31
31
32
- export function makeFormatCodeOptions ( fileName : string , opts : Options , formatSettings : ts . FormatCodeSettings ) : ts . FormatCodeSettings {
32
+ export async function makeFormatCodeOptions ( fileName : string , opts : Options , formatSettings : ts . FormatCodeSettings ) : Promise < ts . FormatCodeSettings > {
33
33
34
34
let baseDir = opts . baseDir ? path . resolve ( opts . baseDir ) : path . dirname ( path . resolve ( fileName ) ) ;
35
35
let configFileName : string | null ;
@@ -46,20 +46,25 @@ export function makeFormatCodeOptions(fileName: string, opts: Options, formatSet
46
46
console . log ( `read ${ configFileName } for ${ fileName } ` ) ;
47
47
}
48
48
49
- let config : TslintSettings = parseJSON ( fs . readFileSync ( configFileName , "utf-8" ) ) ;
50
- if ( ! config . rules ) {
49
+ const { Configuration } = await import ( "tslint" ) ;
50
+ const { rules } = Configuration . loadConfigurationFromPath ( configFileName ) ;
51
+
52
+ if ( ! rules ) {
51
53
return formatSettings ;
52
54
}
53
- if ( config . rules . indent && config . rules . indent [ 0 ] ) {
54
- if ( config . rules . indent [ 1 ] === "spaces" ) {
55
+ const indent = rules . get ( "indent" ) ;
56
+ const whitespace = rules . get ( "whitespace" ) ;
57
+
58
+ if ( indent && indent . ruleArguments ) {
59
+ if ( indent . ruleArguments [ 0 ] === "spaces" ) {
55
60
formatSettings . convertTabsToSpaces = true ;
56
- } else if ( config . rules . indent [ 1 ] === "tabs" ) {
61
+ } else if ( indent . ruleArguments [ 0 ] === "tabs" ) {
57
62
formatSettings . convertTabsToSpaces = false ;
58
63
}
59
64
}
60
- if ( config . rules . whitespace && config . rules . whitespace [ 0 ] ) {
61
- for ( let p in config . rules . whitespace ) {
62
- let value = config . rules . whitespace [ p ] ;
65
+ if ( whitespace && whitespace . ruleArguments ) {
66
+ for ( let p in whitespace . ruleArguments ) {
67
+ let value = whitespace . ruleArguments [ p ] ;
63
68
if ( value === "check-branch" ) {
64
69
formatSettings . insertSpaceAfterKeywordsInControlFlowStatements = true ;
65
70
} else if ( value === "check-decl" ) {
0 commit comments