Skip to content

Bad formatting on saving with non-semi code style #3715

@Withered-Flower-0422

Description

@Withered-Flower-0422

Steps

Let's take a look at the code below:

/** @type {any} */ let foo;

console.log(42);

/** @type {string[]} */ (foo).forEach((bar) => console.log(bar));

Everything goes well when the config semi is true.

But after I set semi to false and save the code, the code will be formatted to the style as below:

/** @type {any} */ let foo

console.log(42)

/** @type {string[]} */ ;(foo).forEach((bar) => console.log(bar))

Prettier added a semicolon before the variable foo, which made foo lose the type string[] and bar lose the type string.

And if I save the code again, the code will be reformatted again as shown below:

/** @type {any} */ let foo

console.log(42)

/** @type {string[]} */
foo.forEach((bar) => console.log(bar))

Expected result

The code should be formatted to the style as below when on saving:

/** @type {any} */ let foo

console.log(42)

;/** @type {string[]} */ (foo).forEach((bar) => console.log(bar))

The semicolon should be added before the comments, so foo and bar can own the type I give.

VS Code Version: 1.100.3

Prettier Extension Version: 11.0.0

OS and version: Windows 11 24H2 26100.4202

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions