typescript-formatter icon indicating copy to clipboard operation
typescript-formatter copied to clipboard

Control block formatting

Open ghost opened this issue 8 years ago • 1 comments

I would like to know if the following can be accomplished with the typescript-formatter options that are currently available.

Take this control block here:

if (true) {
    // do something
} else {
    // do something else
}

Using my settings (see below) the formatter converts it to

if (true)
{
    // do something
} else
{
    // do something else
}

Is there a way to format it so that the "else" is in a new line? It should look like this:

if (true)
{
    // do something
}
else
{
    // do something else
}

What would be the best way to define such a rule? Insert a newline after the closing brace, or insert a newline before the "else"?

Here are my options for typescript-formatter

{
    "insertSpaceAfterCommaDelimiter": true,
    "insertSpaceAfterSemicolonInForStatements": true,
    "insertSpaceBeforeAndAfterBinaryOperators": true,
    "insertSpaceAfterConstructor": false,
    "insertSpaceAfterFunctionKeywordForAnonymousFunctions": false,
    "insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis": false, // ()
    "insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets": false, // []
    "insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces": true, // {}
    //   "insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces": false,
    //   "insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces": false,
    //   "insertSpaceAfterTypeAssertion": false,
    //   "insertSpaceBeforeFunctionParenthesis": false,
    "placeOpenBraceOnNewLineForFunctions": true,
    "placeOpenBraceOnNewLineForControlBlocks": true
}

ghost avatar Apr 28 '17 09:04 ghost

sorry, I have no idea. Is it can on VSCode or any other editor that uses TypeScript LanguageService?

vvakame avatar May 03 '17 07:05 vvakame