microsoft / microsoft/TypeScript
Feature request: set JS output indentation to 2 in next major release
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.4k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
Suggestion
Rather than make indention configurable per #4042 and #2768, this feature request is to change the default output of the TypeScript compiler to be 2 spaces, in the next major release.
- This is not asking for a configuration option per #\4042 and #\2768, and hence not a duplicate of that feature request or that PR. Rather it is asking for TS to have sensible defaults in its JavaScript output.
- People do occasionally need to look at TypeScript output hence TypeScript output should look like idiomatic JavaScript.
- 2 spaces is a sensible default for JavaScript output because:
- 7 of the 8 most popular JavaScript style guides use 2 spaces. The jQuery guidelines use tabs:
- Prettier
tabWidth default is 2, useTabs default is false 2️⃣
- StandardJS
Use 2 spaces for indentation. 2️⃣
- node style guide
Use 2 spaces for indenting your code. 2️⃣
- Idiomatic JS
For readability, I always recommend setting your editor's indent size to two characters — this means two spaces or two spaces representing a real tab 2️⃣
- AirBnB style guide
19.1 Use soft tabs (space character) set to 2 spaces 2️⃣
- MDN code style guide
Mark indentation with 2 spaces. 2️⃣
- Google JavaScript Style Guide
Each time a new block or block-like construct is opened, the indent increases by two spaces. 2️⃣
- jQuery
Indentation with tabs.
- Prettier
- All of the documentation for the well known APIs below:
- The vast majority of npm modules use 2 spaces. I can't find stats here but I'd be surprised if it was lower than 97%. Going through the npm js top 10, 7 of the top 10 use 2 spaces, 1 uses tabs, tslib and moment are the only projects that use four spaces.
- Well known JS playgrounds:
- 7 of the 8 most popular JavaScript style guides use 2 spaces. The jQuery guidelines use tabs:
Summarizing the above, the other well known 4-space style guides, APIs and projects asides from TypeScript are:
- moment JS
This is the end of the list.
🔍 Search Terms
I searched for TS output indentation and came up with #4042 and #2768, which do not propose the same thing as this feature request, which is a sensible value in TS's output JS where 'sensible' is defined as looking like JavaScript.
✅ Viability Checklist
My suggestion meets these guidelines:
- [🤔] This wouldn't change input TS, but would change output JS. Not sure whether that's considered a breaking change, hence 'next major release'.
- [✅] 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, new syntax sugar for JS, etc.)
- [✅✅✅✅✅] This feature would very much agree with the rest of TypeScript's Design Goals! Specifically "Emit clean, idiomatic, recognizable JavaScript code.". Right now the JS output by the TS compiler is not idiomatic or recognisable.
⭐ Suggestion
Change the number from 4 to 2 so it matches JavaScript. Not asking for a configuration option. TS should have sensible defaults. Sensible defaults for JavaScript include looking like the vast majority of other JavaScript.
📃 Motivating Example
See the links above.
💻 Use Cases
I and many others (according to #4042 and #2768) often look at outputted JS. For example, right now I want to throw debugger into some dist JS in my node_modules folder to see why a third party library is behaving oddly. I have to read some very odd-looking JavaScript since the TS compiler doesn't use a sensible default for the indentation value.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
La issue non indica file, test o punti di ingresso. Inizia individuando la gestione dell'indentazione dell'output JavaScript del compilatore e le baseline dell'output correlate; il lavoro è completato quando l'indentazione emessa per impostazione predefinita è di 2 spazi senza aggiungere un'opzione di configurazione e i test interessati sono aggiornati e passano.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- javascript, typescript
- Ambito
- compilers
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100