Skip to content

Add support for insertSpaceAfterOpeningAndBeforeClosingEmptyBraces #167

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/provider/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface TsfmtSettings {
insertSpaceAfterFunctionKeywordForAnonymousFunctions?: boolean;
insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis?: boolean;
insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets?: boolean;
insertSpaceAfterOpeningAndBeforeClosingEmptyBraces?: boolean;
insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces?: boolean;
insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces?: boolean;
insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces?: boolean;
Expand All @@ -32,7 +33,11 @@ interface TsfmtSettings {
convertTabsToSpaces?: boolean;
}

export function makeFormatCodeOptions(fileName: string, opts: Options, formatSettings: ts.FormatCodeSettings): ts.FormatCodeSettings {
export type Writable<T> = {
-readonly [K in keyof T]: T[K];
};

export function makeFormatCodeOptions(fileName: string, opts: Options, formatSettings: Writable<ts.FormatCodeSettings>): ts.FormatCodeSettings {
let baseDir = opts.baseDir ? path.resolve(opts.baseDir) : path.dirname(path.resolve(fileName));
let configFileName: string | null;
if (opts.tsfmtFile && path.isAbsolute(opts.tsfmtFile)) {
Expand Down Expand Up @@ -70,6 +75,9 @@ export function makeFormatCodeOptions(fileName: string, opts: Options, formatSet
if (typeof config.insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis === "boolean") {
formatSettings.insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis = config.insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis;
}
if (typeof config.insertSpaceAfterOpeningAndBeforeClosingEmptyBraces === "boolean") {
formatSettings.insertSpaceAfterOpeningAndBeforeClosingEmptyBraces = config.insertSpaceAfterOpeningAndBeforeClosingEmptyBraces;
}
if (typeof config.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces === "boolean") {
formatSettings.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces = config.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces;
}
Expand Down
3 changes: 2 additions & 1 deletion lib/provider/tslintjson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import * as path from "path";

import { Options } from "../";
import { getConfigFileName } from "../utils";
import { Writable } from "./base";


export interface AdditionalFormatSettings {
$noConsecutiveBlankLines: boolean;
}

export async function makeFormatCodeOptions(fileName: string, opts: Options, formatSettings: ts.FormatCodeSettings): Promise<ts.FormatCodeSettings> {
export async function makeFormatCodeOptions(fileName: string, opts: Options, formatSettings: Writable<ts.FormatCodeSettings>): Promise<ts.FormatCodeSettings> {

const rules = await getRules(fileName, opts);

Expand Down
7 changes: 6 additions & 1 deletion lib/provider/vscodesettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as fs from "fs";

import { Options } from "../";
import { getConfigFileName, parseJSON } from "../utils";
import { Writable } from "./base";

// https://code.visualstudio.com/Docs/customization/userandworkspace
interface VSCodeSettings {
Expand All @@ -16,6 +17,7 @@ interface VSCodeSettings {
"typescript.format.insertSpaceAfterFunctionKeywordForAnonymousFunctions": boolean;
"typescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis": boolean;
"typescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets": boolean;
"typescript.format.insertSpaceAfterOpeningAndBeforeClosingEmptyBraces": boolean;
"typescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces": boolean;
"typescript.format.insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces": boolean;
"typescript.format.insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces": boolean;
Expand All @@ -28,7 +30,7 @@ interface VSCodeSettings {
// baseIndentSize
}

export function makeFormatCodeOptions(fileName: string, opts: Options, formatSettings: ts.FormatCodeSettings): ts.FormatCodeSettings {
export function makeFormatCodeOptions(fileName: string, opts: Options, formatSettings: Writable<ts.FormatCodeSettings>): ts.FormatCodeSettings {

let baseDir = opts.baseDir ? path.resolve(opts.baseDir) : path.dirname(path.resolve(fileName));
let configFileName: string | null;
Expand Down Expand Up @@ -72,6 +74,9 @@ export function makeFormatCodeOptions(fileName: string, opts: Options, formatSet
if (config["typescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces"] != null) {
formatSettings.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces = config["typescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces"];
}
if (config["typescript.format.insertSpaceAfterOpeningAndBeforeClosingEmptyBraces"] != null) {
formatSettings.insertSpaceAfterOpeningAndBeforeClosingEmptyBraces = config["typescript.format.insertSpaceAfterOpeningAndBeforeClosingEmptyBraces"];
}
if (config["typescript.format.insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces"] != null) {
formatSettings.insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces = config["typescript.format.insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces"];
}
Expand Down
Loading