PHPStorm reformat - how do I disable removing spaces in empty lines?
Asked Answered
B

2

16

When reformatting a file, phpstorm replaces empty lines with whitespace to just empty lines, e.g. ^[tab][tab]$ to ^$. How do I disable this?

Barri answered 3/6, 2014 at 11:2 Comment(5)
Why do you care about spaces on empty lines?Broomstick
Because some developers use IDEs which place tabs in empty lines, so reformat will remove these every time and add a lot of useless info to git diffs.Barri
diff has an option to ignore whitespace differences. Doesn't git diff allow you to use that option?Broomstick
Github doesn't seem to have that option I guess? Actually, I don't care if there are or are not spaces in empty lines, so I'd want phpstorm to act accordingly.Barri
because, we can't always specify "ignore white spaces" on a git add/commit based on tools, and suddenly a 1-3 line correction submitted for review indicates half the file was changed!Candra
D
24

You cannot -- http://youtrack.jetbrains.com/issue/IDEA-73161

I was thinking that disabling stripping whitespace characters altogether would do the job:

By changing Settings | Editor | Strip trailing spaces on Save (which nowadays has Modified Lines option)

but apparently it only works on "Save".

Related tickets:


Now you can do that on code reformat as well:

  1. Settings/Preferences
  2. Editor | Code Style
  3. $language$ | Tabs and Indents | Keep indents on empty lines check box

(this option was introduced after this answer was provided: https://youtrack.jetbrains.com/issue/IDEA-103941#comment=27-807213)

Disproportion answered 3/6, 2014 at 11:10 Comment(4)
I've set "strip trailing spaces on Save" to "None". But reformat still acts as I've described originally. Is this expected?Barri
"Yes" and "No" at the same time. "Yes" because right now it cannot be avoided (for whatever reason -- see above mentioned ticket IDEA-73161) and "No" because I would expect that the above option to work even during reformat. I will alter my answer a bit.Disproportion
Is it possible to disable striping spaces on .blade.php files, but enable it for all other files (including index.php etc.) ?Aldos
@Aldos Using .editorconfig file (it has standard option fir such stuff) & enabled EditorConfig support in IDE settings -- yes, that should work fine (even on per file level, if configured properly). NOTE: When enabled, settings from .editorconfig override IDE settings.Disproportion
L
2

I find solution in opposite topic: Configure editor to remove whitespaces in blank lines.

It works in WebStorm, and should work in PHPStorm as well:

Settings | Editor | Code Style | PHP | Tabs and Indents (tab) | Keep Indents on Empty Lines" (check box)

Laryngotomy answered 3/2, 2017 at 9:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.