Suggestion: Formatting: Disable inserting spaces around leading semicolon
#48 571 ouverte le 5 avr. 2022
Métriques du dépôt
- Stars
- (48 455 stars)
- Métriques de merge PR
- (Merge moyen 6j 17h) (9 PRs mergées en 30 j)
Description
Suggestion
🔍 Search Terms
semicolon at the start of a line formatting spaces around semi
✅ Viability 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, new syntax sugar for JS, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
⭐ Suggestion
In setups where semicolons are not used and the code relies on ASI, there are certain statements which can confuse both the developer and the engine. In such cases, some people prefer to use semicolon at the start of the particular statement that could potentially cause such behavior regardless of what is actually on the preceding line.
📃 Motivating Example
This adjustment will fix formatting issue and make it consistent.
💻 Use Cases
With vscode formatting setting
"typescript.format.semicolons": "remove"
and eslint rules,
"semi-style": ["error", "first"],
"semi-spacing": "error"
"indent": ["error", 2],
I get this automatic eslint --fix,
// before
console.log('hi');
(something ??= {_default: 0})[key] = 1
// after
console.log('hi')
;(something ??= {_default: 0})[key] = 1
^ ..... this is desired
which is then auto-formatted by vscode to this,
console.log('hi')
; (something ??= {_default: 0})[key] = 1
^^ ^ ..... spaces inserted, undesired
which in turn raises this eslint error.
Expected indentation of 14 spaces but found 16. eslint(indent)
Migrated from https://github.com/microsoft/vscode/issues/146620