Skip to content

Commit b9195b3

Browse files
committed
refactor(tsfmt): change editorconfig post processing logic
1 parent 98fa0e5 commit b9195b3

File tree

5 files changed

+29
-3
lines changed

5 files changed

+29
-3
lines changed

lib/provider/editorconfig.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export default function makeFormatCodeOptions(fileName: string, opts: Options, f
4545
}
4646

4747

48-
export function postProcess(fileName: string, formattedCode: string, opts: Options, formatOptions: ts.FormatCodeOptions): Promise<string> {
48+
export function postProcess(fileName: string, formattedCode: string, opts: Options, _formatOptions: ts.FormatCodeOptions): Promise<string> {
4949

5050
if (opts.verbose && opts.baseDir && !emitBaseDirWarning) {
5151
console.log("editorconfig is not supported baseDir options");
@@ -55,8 +55,8 @@ export function postProcess(fileName: string, formattedCode: string, opts: Optio
5555
return editorconfig
5656
.parse(fileName)
5757
.then(config => {
58-
if (config.insert_final_newline) {
59-
return formattedCode.replace(/\s+$/, formatOptions.NewLineCharacter);
58+
if (config.insert_final_newline && !/\n$/.test(formattedCode)) {
59+
formattedCode += "\n";
6060
}
6161
return formattedCode;
6262
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"IndentSize": 4,
3+
"TabSize": 4,
4+
"IndentStyle": 2,
5+
"NewLineCharacter": "\r\n",
6+
"ConvertTabsToSpaces": true,
7+
"InsertSpaceAfterCommaDelimiter": true,
8+
"InsertSpaceAfterSemicolonInForStatements": true,
9+
"InsertSpaceBeforeAndAfterBinaryOperators": true,
10+
"InsertSpaceAfterKeywordsInControlFlowStatements": true,
11+
"InsertSpaceAfterFunctionKeywordForAnonymousFunctions": false,
12+
"InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis": false,
13+
"InsertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets": false,
14+
"InsertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces": false,
15+
"PlaceOpenBraceOnNewLineForFunctions": false,
16+
"PlaceOpenBraceOnNewLineForControlBlocks": false
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log("test");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# EditorConfig is awesome: http://EditorConfig.org
2+
3+
# top-most EditorConfig file
4+
root = true
5+
6+
[*]
7+
insert_final_newline=true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log("test");

0 commit comments

Comments
 (0)