6

I'm using prettier in VS Code for typescript. It always remove extra parenthesis, for example

(new Controller()).setData(data).run();

will always be format into

new Controller().setData(data).run();

Which rules handle this deletion? I did see a similar rule in eslint: no-extra-parens. However, I am not using this rule in my eslint file.

rioV8
  • 24,506
  • 3
  • 32
  • 49
Nick Yang
  • 71
  • 2
  • FWIW, parentheses are useless in this code, `new Ctor().method()` is the way it's commonly written in JS, this is the problem that Prettier addresses. – Estus Flask Jun 11 '21 at 08:18
  • @EstusFlask the fact it still works is certainly not the point of this Q ;-) – jave.web Apr 10 '22 at 09:08
  • I have the same issue with math expressions `y + (height / 2)` will be formatted into `y + height / 2` which is different result – Safwat Fathi Jan 01 '23 at 09:19

1 Answers1

0

Add a file .prettierrc in the project's root folder with the following contents.

module.exports = {
  arrowParens: "avoid"
};

Refer to this answer.

CodeBird
  • 387
  • 1
  • 8