Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebStorm PhpStorm code reformat: how to fix comments?

WebStorm and PhpStorm allow you to reformat your code to fit the coding style set in settings (e.g.: indentation space)

I'm using this measure to fix some of the many lint errors in my project but I'm stuck at one point: is it possible to reformat all // comments to begin with a space? To go from

//My comment

to

// My comment

If a comment already begins with a space character, it should be left alone.

Edit: There is an option in:

  • "Settings >> Editor >> Code Style >> {{coding lang}} >> Other tab" to set a blank space at the start of each comment (see "Comment code" section at the bottom of this image).

enter image description here

However, even with that selected, using the "Reformat code" option does not fix the comments.

like image 528
BeetleJuice Avatar asked Sep 05 '25 17:09

BeetleJuice


1 Answers

'Add a space at comment start' option only affects 'Comment with line comment' action (Ctrl+/) behavior, it is not used by formatter.

There is currently no way to insert leading spaces on formatting, please vote for WEB-26244

like image 76
lena Avatar answered Sep 10 '25 12:09

lena