Autoformat for PHPDoc and arguments

Greetings.

Surely there are questions similar to mine, but I can't get the right words. I'm sorry.

 

In the project I'm working on, when I declare __construct arguments and PHPDoc params, I usually write type + whitespace + name.

Sometimes PHPStorm automatically formats these to align variable names at the same column.

I received some commit changes from partners, which were basically adding whitespaces like that, probably made automatically.

 

Is there any way to set a standard around this, to everyone in the project to follow and write them the same way? Something like editorconfig helping us establish 4-space indentation.

At the very least I would like to know the name of this technique, or which PHPStorm menu action does this autoformat, or if there's any PSR rule about this.

 

Example:

string $name

int $age

 

Avoid converting it to

string $name

int    $age

评论操作 固定链接

Hi there,

All code formatting stuff for this can be found at "Settings/Preferences | Editor | Code Style | PHP"

In your case you should check "PHPDoc | Align parameter/property names" option.

1
评论操作 固定链接

Yes! That's what I'm talking about.

Thank you, Andriy. Have a nice day!

Through a quick search, I see that editorconfig doesn't have any option related to this. At least, for PHP.
So it's time to discuss it with my partners. 😅

0
评论操作 固定链接

Through a quick search, I see that editorconfig doesn't have any option related to this.

Yes, .editorconfig provides only basic (most common) editor settings.

But with PhpStorm you can export your whole current Code Style into the .editorconfig file (all entries will have ij_ prefix and will be specific to IDEA-based IDEs only ofc) and leave only the needed options:

Or you can write them manually (just keep in mind that it might happen that the IDE may not list all possible options in such a case, e.g. due to a bug/internal misconfig).

https://www.jetbrains.com/help/phpstorm/configuring-code-style.html#editorconfig

Sadly I cannot say how "transparent" this will be: will editing an option in the .editorconfig file reflect it's status in the GUI or other way around? In other words: will the IDE keep the GUI and .editorconfig file in sync for such options? Never tried it myself (had no need) so cannot advise on this part.

0

请先登录再写评论。