Skip to content

Commit f079026

Browse files
committed
Merge branch 'SweetIQ-applyeditfix'
2 parents 248e114 + 77f617d commit f079026

File tree

4 files changed

+64
-0
lines changed

4 files changed

+64
-0
lines changed

lib/formatter.ts

+9
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ export default function format(fileName: string, text: string, options = createD
2727
function applyEdits(text: string, edits: ts.TextChange[]): string {
2828
// Apply edits in reverse on the existing text
2929
let result = text;
30+
31+
// An issue with `ts.formatting.formatDocument` is that it does
32+
// not always give the edits array in ascending order of change start
33+
// point. This can result that we add or remove some character in
34+
// the begining of the document, making the all the other edits
35+
// offsets invalid.
36+
37+
// We resolve this by sorting edits by ascending start point
38+
edits.sort((a, b) => a.span.start - b.span.start);
3039
for (let i = edits.length - 1; i >= 0; i--) {
3140
let change = edits[i];
3241
let head = result.slice(0, change.span.start);

test/expected/schemats/main.json

+17
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+
}

test/expected/schemats/main.ts

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* AUTO-GENERATED FILE @ 2016-12-07 13:17:46 - DO NOT EDIT!
3+
*
4+
* This file was generated with schemats node package:
5+
* $ schemats generate -c postgres://username:password@localhost/test -t users -o ./test/osm.ts
6+
*
7+
* Re-run the command above.
8+
*/
9+
10+
11+
export namespace cta_situationcompte_scoFields {
12+
export type sco_id = number;
13+
export type sco_total_debit = number;
14+
export type sco_total_credit = number;
15+
export type sco_nb_ecritures = number;
16+
export type pst_id = number;
17+
export type cpt_id = number;
18+
19+
}

test/fixture/schemats/main.ts

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* AUTO-GENERATED FILE @ 2016-12-07 13:17:46 - DO NOT EDIT!
3+
*
4+
* This file was generated with schemats node package:
5+
* $ schemats generate -c postgres://username:password@localhost/test -t users -o ./test/osm.ts
6+
*
7+
* Re-run the command above.
8+
*/
9+
10+
11+
export namespace cta_situationcompte_scoFields {
12+
export type sco_id = number;
13+
export type sco_total_debit = number;
14+
export type sco_total_credit = number;
15+
export type sco_nb_ecritures = number;
16+
export type pst_id = number;
17+
export type cpt_id = number;
18+
19+
}

0 commit comments

Comments
 (0)