如何在PhpStorm中保留行尾PHPdoc注释不自动换行?
如何让PhpStorm保留行尾的PHPdoc注释不自动换行
你可以通过调整PhpStorm的代码风格设置实现需求,具体步骤如下:
- 打开PhpStorm设置:使用快捷键
Ctrl+Alt+S(Windows/Linux)或Cmd+,(Mac)。 - 依次进入
Editor > Code Style > PHP,切换到Code Generation标签页。 - 在「Commenting code」区域,勾选Place documentation comment at line end选项。
- (可选)如果数组内注释仍有问题,切换到
Wrapping and Braces标签页,找到Arrays部分,确保未开启强制将注释换行的相关选项。
设置完成后,重新格式化代码(快捷键Ctrl+Alt+L/Cmd+Opt+L),行尾的PHPdoc注释就会保持在代码行末尾,不会被自动换行到新行。
比如你的示例代码,格式化后会保留成期望样式:
[ 'configFoo' => ['some' => true], /** @see Foo::some */ 'configBar' => ['baz' => true] /** @see Bar::baz */ ] //... $a = 42; /** @link https://fakewikipedia.com/The_Answer_to_the_Ultimate_Question_of_Life */ $b = 1; /** @see ExternalDocumentation */
内容的提问来源于stack exchange,提问作者j. Doe
相关产品推荐
相关产品推荐

