When reformatting a file, phpstorm replaces empty lines with whitespace to just empty lines, e.g. ^[tab][tab]$
to ^$
. How do I disable this?
Asked
Active
Viewed 1.1k times
16

Fluffy
- 27,504
- 41
- 151
- 234
-
Why do you care about spaces on empty lines? – Barmar Jun 03 '14 at 11:04
-
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. – Fluffy Jun 03 '14 at 11:06
-
`diff` has an option to ignore whitespace differences. Doesn't `git diff` allow you to use that option? – Barmar Jun 03 '14 at 11:11
-
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. – Fluffy Jun 03 '14 at 11:15
-
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! – ppostma1 Sep 27 '16 at 20:01
2 Answers
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 hasModified Lines
option)
but apparently it only works on "Save".
Related tickets:
Now you can do that on code reformat as well:
Settings/Preferences
Editor | Code Style
$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)

Top-Master
- 7,611
- 5
- 39
- 71

LazyOne
- 158,824
- 45
- 388
- 391
-
1I've set "strip trailing spaces on Save" to "None". But reformat still acts as I've described originally. Is this expected? – Fluffy Jun 03 '14 at 11:18
-
1"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. – LazyOne Jun 03 '14 at 12:07
-
Is it possible to disable striping spaces on `.blade.php` files, but enable it for all other files (including index.php etc.) ? – Adam Dec 17 '20 at 17:19
-
@Adam 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. – LazyOne Dec 17 '20 at 17:31
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)

coderaiser
- 749
- 5
- 15