Php-cs-fixer: [OrderedImportsFixer] Ability to add blank line between groups

Created on 7 Mar 2018  路  3Comments  路  Source: FriendsOfPHP/PHP-CS-Fixer

OrderedImportsFixer should have a blankLineBetweenGroups config option, which when used together with

'importsOrder' => ['class', 'function', 'const']

would allow adherence to the draft PSR-12.

Example taken from the draft PSR:

use Vendor\Package\{ClassA as A, ClassB, ClassC as C};
use Vendor\Package\SomeNamespace\ClassD as D;
use Vendor\Package\AnotherNamespace\ClassE as E;

use function Vendor\Package\{functionA, functionB, functionC};
use function Another\Vendor\functionD;

use const Vendor\Package\{CONSTANT_A, CONSTANT_B, CONSTANT_C};
use const Another\Vendor\CONSTANT_D;
kinfeature request

Most helpful comment

I do believe that it could be achieved as separated fixer (that fix only one thing instead of all different issues with imports)

Maybe, a new fixer in combination with #3586, sth like grouped_imports, that:

  • collects all imports in given namespace to put them together (#3586)
  • optionally, add blank line between different type of imports

shall run after ordered_imports

All 3 comments

I do believe that it could be achieved as separated fixer (that fix only one thing instead of all different issues with imports)

Maybe, a new fixer in combination with #3586, sth like grouped_imports, that:

  • collects all imports in given namespace to put them together (#3586)
  • optionally, add blank line between different type of imports

shall run after ordered_imports

@keradus the problem with your proposed fixer is that if first ordered_imports is run, it orders the imports with the "flaw" as described in #3586 and when the new fixer then "collects all imports in given namespace to put them together" it either becomes unordered, or it needs to again do things that ordered_imports already does (figuring out exactly where in the sort-order it should be, and thus needing the config of ordered_imports as well).

Therefore they need to become 3 fixers (run in this order):

  • #3586 Collecting all imports
  • ordered_imports for sorting them
  • New fixer adding blank line between import types.

Unless you add the last as option to ordered_imports like this feature request describes 馃槈

What's the status here?

Was this page helpful?
0 / 5 - 0 ratings