typescript-formatter
typescript-formatter copied to clipboard
Control block formatting
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
}
sorry, I have no idea. Is it can on VSCode or any other editor that uses TypeScript LanguageService?