microsoft / microsoft/TypeScript
Language services formatting for `else` on newline
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.4k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
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.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne damit, die Formatter-Einstiegspunkte zu finden, die für die TypeScript-Formatierung in VS Code und dem Befehlszeilenprogramm typescript-formatter verwendet werden, und verfolge dann die Verarbeitung von geschweiften Klammern von Kontrollblöcken. Vergleiche die aktuellen und erwarteten Beispiele; fertig ist es, wenn der konfigurierte Zeilenumbruchstil else in einer eigenen Zeile platziert, ohne das sonstige Formatierungsverhalten zu ändern.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- tooling
- Issue-Typ
- Feature
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100