Search code examples
phpphpstorm

PhpStorm does not reformat the complete code properly


Since I have many (bad coded/indented) files, that look like this: enter image description here

After doing a reformat, most code is indented right, but some parts still look like this: enter image description here

After having a closer look (with sublime) I noticed that these lines are not indented with tabs, but with spaces: enter image description here

So why are those parts not indented right with tabs?

Additional question: How can I remove the empty lines for the hole project?


Solution

  • The issue with spaces instead of tabs and original indentation -- you need to remove span from the "Keep white spaces inside" list in Code Style for HTML.

    Empty lines -- most of them you can get rid if you disable "Keep line breaks" sort of options and put 0 into "Maximum black lines" kind of fields -- there quite a few of them in each language (HTML & PHP in your case).

    Unfortunately those options do not seem to have any effect on empty lines between PHP code blocks (between '?> and <?php). For such cases I suggest use regex and replace \n\n (2 line endings in a row) by single \n (you may need to run such replacement few times if you have lots of consecutive empty lines).