microsoft / microsoft/TypeScript

Language services formatting for `else` on newline

Aperta
#41,777 2 commenti 3 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Awaiting More Feedback Suggestion
Lingua principale
Go
Stelle
111k
Fork
14.3k
Merge medio
2g 4h
PR unite (30g)
132

Descrizione

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.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia individuando i punti di ingresso del formatter utilizzati per la formattazione di TypeScript in VS Code e nel typescript-formatter da riga di comando, quindi segui la gestione delle parentesi graffe dei blocchi di controllo. Confronta gli esempi attuali e quelli attesi; il lavoro è completato quando lo stile di nuova riga configurato posiziona else su una riga separata senza modificare nessun altro comportamento di formattazione.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
typescript
Ambito
tooling
Tipo di issue
Funzionalità
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.