microsoft / microsoft/TypeScript
Language services formatting for `else` on newline
オープン
まだ誰も着手していません。
Awaiting More Feedback
Suggestion
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
Search Terms
- format else
- formatted else
- fomatter newline
- formatting newline
Suggestion
When the formatting option for the opening brace on newline for control blocks is true, it would make sense to have the else on it's online as well.
Use Cases
Using typescript-formatter with VS Code, and from command line.
Examples
My tsfmt.json is:
{
"baseIndentSize": 0,
"indentSize": 4,
"tabSize": 4,
"indentStyle": 2,
"newLineCharacter": "\n",
"convertTabsToSpaces": true,
"insertSpaceAfterCommaDelimiter": true,
"insertSpaceAfterSemicolonInForStatements": true,
"insertSpaceBeforeAndAfterBinaryOperators": true,
"insertSpaceAfterConstructor": false,
"insertSpaceAfterKeywordsInControlFlowStatements": true,
"insertSpaceAfterFunctionKeywordForAnonymousFunctions": false,
"insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis": false,
"insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets": false,
"insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces": true,
"insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces": false,
"insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces": false,
"insertSpaceAfterTypeAssertion": false,
"insertSpaceBeforeFunctionParenthesis": false,
"insertSpaceBeforeTypeAnnotation": false,
"placeOpenBraceOnNewLineForFunctions": true,
"placeOpenBraceOnNewLineForControlBlocks": true
}
I get results like this:
if(condition)
{
console.log('condition true');
} else if(otherCondition)
{
console.log('other condition is true');
} else
{
console.log('condition not true');
}
For people using "placeOpenBraceOnNewLineForControlBlocks": true, the expected behaviour (IMHO) would be:
if(condition)
{
console.log('condition true');
}
else if(otherCondition)
{
console.log('other condition is true');
}
else
{
console.log('condition not true');
}
Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、VS Code とコマンドラインの typescript-formatter で TypeScript のフォーマットに使用されている formatter のエントリポイントを特定し、次に制御ブロックの波括弧の処理を追跡します。現在の例と期待される例を比較します。設定された改行スタイルによって else が独立した行に配置され、他のフォーマット動作が変更されなければ完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- tooling
- issue の種類
- 機能追加
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100