Disable autoformat in IntelliJ / PHPStorm

When using IntelliJ or PHPStorm as IDE, I use the autoformat for code (Code -> Reformat Code or Ctrl+Alt+L). It works great. But in some cases I need to disable autoformat for some parts of the code.

This is how you can disable autoformat in your code:

// @formatter:off
echo 'HERE COMES A LOT' . 
                 ' OF UNFORMATED CODE NOW! :-)';
$aArray=array('Not', $formated, "too!");

// @formatter:on
echo 'This will' . 
                 ' be formatted again! :-)';
$aArray=array('This will be', $formated, "too!");

The result after executing the autoformat command (Code -> Reformat Code or Ctrl+Alt+L) would be (with my setings):

// @formatter:off
echo 'HERE COMES A LOT' . 
                 ' OF UNFORMATED CODE NOW! :-)';
$aArray=array('Not', $formated, "too!");

// @formatter:on
echo 'This will' . ' be formatted again! :-)';
$aArray = [
    'This will be', 
    $formated, 
    'too!'
];

Further information about disable autoformat:

Can be found under https://stackoverflow.com/questions/3375307/how-to-disable-code-formatting-for-some-part-of-the-code-using-comments. Here you also find, how to set it up.

Leave a Reply

Your email address will not be published. Required fields are marked *

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.