prettier icon indicating copy to clipboard operation
prettier copied to clipboard

Align formatting of `%` with `/` and `*`

Open nicolo-ribaudo opened this issue 6 months ago • 1 comments

This is related to https://github.com/prettier/prettier/issues/187. However, this issue is about one specific operator.

Unfortunately GH search is not very good when searching for symbols, so I couldn't find if there is already a similar issue.

Prettier 3.5.3 Playground link

# Options (if any):

Input:

let high = num % 256 - 128;
let high = num / 256 - 128;

Output:

let high = (num % 256) - 128;
let high = num / 256 - 128;

Expected output:

let high = num % 256 - 128;
let high = num / 256 - 128;

or

let high = (num % 256) - 128;
let high = (num / 256) - 128;

Why?

%, * and / all have the same precedence in JavaScript, so I would expect them to be formatted the same way.

nicolo-ribaudo avatar Jun 11 '25 21:06 nicolo-ribaudo

It seems intentional ... https://github.com/prettier/prettier/pull/4413

fisker avatar Jun 11 '25 23:06 fisker