JS Arrow Functions Parentheses

Hi.

Is there an option to remove parentheses if there's only one parameter name in an arrow function when I reformat code?

(singleParam) => { statements }

Reformatted

singleParam => { statements }

 

Thank you.

0
5 comments

There is Remove unnecessary parentheses quick fix, available on Alt+Enter:

 

0
Avatar
Permanently deleted user

Thanks!

0
Avatar
Permanently deleted user

Is there any way to add that into the codestyle formatter, to have it perform that option on the whole file?

2

You can:

 

  • Alt+Enter, then select Fix all 'unnecessary parentheses' problems in file to fix all parentheses in file
  • Alt+Enter, then Cleanup code to fix this and all similar 'safe' problems

 

 

 

0

Just wanted to share the solution to my problem as well.

I'm using Prettier for reformatting with a custom keymap (Shift + Cmd + P) and it added an unnecessary parentheses on every format.

Setting Prettier config property arrowParens to "avoid" removes the unnecessary parentheses, like this:

"arrowParens": "avoid"

Prettier documentation here

1

Please sign in to leave a comment.