@@ -5,6 +5,7 @@ import * as ts from "typescript";
5
5
import * as path from "path" ;
6
6
import * as fs from "fs" ;
7
7
8
+ import { Options } from "../" ;
8
9
import { getConfigFileName } from "../utils" ;
9
10
10
11
interface TsfmtSettings {
@@ -33,56 +34,58 @@ interface TsfmtSettings {
33
34
convertTabsToSpaces ?: boolean ;
34
35
}
35
36
36
- export default function makeFormatCodeOptions ( fileName : string , options : ts . FormatCodeOptions ) : ts . FormatCodeOptions {
37
+ export default function makeFormatCodeOptions ( fileName : string , opts : Options , formatOptions : ts . FormatCodeOptions ) : ts . FormatCodeOptions {
37
38
"use strict" ;
38
39
39
40
var configFileName = getConfigFileName ( path . dirname ( path . resolve ( fileName ) ) , "tsfmt.json" ) ;
40
41
if ( ! configFileName ) {
41
- return options ;
42
+ return formatOptions ;
43
+ }
44
+
45
+ if ( opts . verbose ) {
46
+ console . log ( `read ${ configFileName } ` ) ;
42
47
}
43
- // console.log("base makeFormatCodeOptions");
44
- // console.log("read " + configFileName);
45
48
46
49
var config : TsfmtSettings = JSON . parse ( < any > fs . readFileSync ( configFileName , "utf-8" ) ) ;
47
50
if ( typeof config . insertSpaceAfterCommaDelimiter === "boolean" ) {
48
- options . InsertSpaceAfterCommaDelimiter = config . insertSpaceAfterCommaDelimiter ;
51
+ formatOptions . InsertSpaceAfterCommaDelimiter = config . insertSpaceAfterCommaDelimiter ;
49
52
}
50
53
if ( typeof config . insertSpaceAfterSemicolonInForStatements === "boolean" ) {
51
- options . InsertSpaceAfterSemicolonInForStatements = config . insertSpaceAfterSemicolonInForStatements ;
54
+ formatOptions . InsertSpaceAfterSemicolonInForStatements = config . insertSpaceAfterSemicolonInForStatements ;
52
55
}
53
56
if ( typeof config . insertSpaceBeforeAndAfterBinaryOperators === "boolean" ) {
54
- options . InsertSpaceBeforeAndAfterBinaryOperators = config . insertSpaceBeforeAndAfterBinaryOperators ;
57
+ formatOptions . InsertSpaceBeforeAndAfterBinaryOperators = config . insertSpaceBeforeAndAfterBinaryOperators ;
55
58
}
56
59
if ( typeof config . insertSpaceAfterKeywordsInControlFlowStatements === "boolean" ) {
57
- options . InsertSpaceAfterKeywordsInControlFlowStatements = config . insertSpaceAfterKeywordsInControlFlowStatements ;
60
+ formatOptions . InsertSpaceAfterKeywordsInControlFlowStatements = config . insertSpaceAfterKeywordsInControlFlowStatements ;
58
61
}
59
62
if ( typeof config . insertSpaceAfterFunctionKeywordForAnonymousFunctions === "boolean" ) {
60
- options . InsertSpaceAfterFunctionKeywordForAnonymousFunctions = config . insertSpaceAfterFunctionKeywordForAnonymousFunctions ;
63
+ formatOptions . InsertSpaceAfterFunctionKeywordForAnonymousFunctions = config . insertSpaceAfterFunctionKeywordForAnonymousFunctions ;
61
64
}
62
65
if ( typeof config . insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis === "boolean" ) {
63
- options . InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis = config . insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis ;
66
+ formatOptions . InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis = config . insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis ;
64
67
}
65
68
if ( typeof config . insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets === "boolean" ) {
66
- options . InsertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets = config . insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets ;
69
+ formatOptions . InsertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets = config . insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets ;
67
70
}
68
71
if ( typeof config . placeOpenBraceOnNewLineForFunctions === "boolean" ) {
69
- options . PlaceOpenBraceOnNewLineForFunctions = config . placeOpenBraceOnNewLineForFunctions ;
72
+ formatOptions . PlaceOpenBraceOnNewLineForFunctions = config . placeOpenBraceOnNewLineForFunctions ;
70
73
}
71
74
if ( typeof config . placeOpenBraceOnNewLineForControlBlocks === "boolean" ) {
72
- options . PlaceOpenBraceOnNewLineForControlBlocks = config . placeOpenBraceOnNewLineForControlBlocks ;
75
+ formatOptions . PlaceOpenBraceOnNewLineForControlBlocks = config . placeOpenBraceOnNewLineForControlBlocks ;
73
76
}
74
77
if ( typeof config . indentSize === "number" ) {
75
- options . IndentSize = config . indentSize ;
78
+ formatOptions . IndentSize = config . indentSize ;
76
79
}
77
80
if ( typeof config . tabSize === "number" ) {
78
- options . TabSize = config . tabSize ;
81
+ formatOptions . TabSize = config . tabSize ;
79
82
}
80
83
if ( typeof config . newLineCharacter === "string" ) {
81
- options . NewLineCharacter = config . newLineCharacter ;
84
+ formatOptions . NewLineCharacter = config . newLineCharacter ;
82
85
}
83
86
if ( typeof config . convertTabsToSpaces === "boolean" ) {
84
- options . ConvertTabsToSpaces = config . convertTabsToSpaces ;
87
+ formatOptions . ConvertTabsToSpaces = config . convertTabsToSpaces ;
85
88
}
86
89
87
- return options ;
90
+ return formatOptions ;
88
91
}
0 commit comments