Skip to content

Suggestion: Formatting: Disable inserting spaces around leading semicolonΒ #48571

@ackvf

Description

@ackvf

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 microsoft/vscode#146620

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions