From 99b3aadce0e6e7de8e2fef502db2ff1811d7a11e Mon Sep 17 00:00:00 2001 From: Damyan Petev Date: Tue, 28 Sep 2021 12:36:30 +0300 Subject: [PATCH] fix(ts-transform): respect quote type from editorconfig --- .../core/typescript/TypeScriptFileUpdate.ts | 3 ++ .../ts-transform/TypeScriptFileUpdate-spec.ts | 30 +++++++++++-------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/packages/core/typescript/TypeScriptFileUpdate.ts b/packages/core/typescript/TypeScriptFileUpdate.ts index 226e8975e..2b24aef4b 100644 --- a/packages/core/typescript/TypeScriptFileUpdate.ts +++ b/packages/core/typescript/TypeScriptFileUpdate.ts @@ -544,6 +544,9 @@ export class TypeScriptFileUpdate { if (options["indent_size"]) { this.formatOptions.indentSize = parseInt(options["indent_size"], 10) || this.formatOptions.indentSize; } + if (options["quote_type"]) { + this.formatOptions.singleQuotes = options["quote_type"] === "single"; + } } if (this.fileSystem.fileExists("tslint.json")) { // tslint prio - overrides other settings diff --git a/spec/unit/ts-transform/TypeScriptFileUpdate-spec.ts b/spec/unit/ts-transform/TypeScriptFileUpdate-spec.ts index 0e45190d8..d389139e2 100644 --- a/spec/unit/ts-transform/TypeScriptFileUpdate-spec.ts +++ b/spec/unit/ts-transform/TypeScriptFileUpdate-spec.ts @@ -536,22 +536,22 @@ describe("Unit - TypeScriptFileUpdate", () => { return false; }); let testTslint = null; - const readsSpy = spyOn(fs, "readFileSync").and.callFake((filePath, opt) => { - if (filePath === ".editorconfig") { - return `# Editor configuration, see http://editorconfig.org - root = true + let editorConfig = `# Editor configuration, see http://editorconfig.org + root = true - [*] - charset = utf-8 - indent_style = space - indent_size = 4 + [*] + charset = utf-8 + indent_style = space + indent_size = 4 - [*.comments] - #nothing in this section + [*.comments] + #nothing in this section - [*.ts] - indent_size = 2 - `; + [*.ts] + indent_size = 2`; + const readsSpy = spyOn(fs, "readFileSync").and.callFake((filePath, opt) => { + if (filePath === ".editorconfig") { + return editorConfig; } else if (testTslint && filePath === "tslint.json") { return JSON.stringify(testTslint); } @@ -564,6 +564,10 @@ describe("Unit - TypeScriptFileUpdate", () => { expect(tsUpdate.getFormatting().spaces).toEqual(true); expect(tsUpdate.getFormatting().singleQuotes).toEqual(false); + editorConfig = editorConfig + "\nquote_type = single"; + tsUpdate.readFormatConfigs(); + expect(tsUpdate.getFormatting().singleQuotes).toEqual(true); + // with tslint existsSpy.and.returnValue({ isFile: () => true }); testTslint = {