Implement index config for GroupImportFixer #7907
Replies: 2 comments
-
Personally I don't find it useful, and it's not even because I don't use grouping at all. I just think it's too generic and is based on non-realistic assumption that namespaces follow sane convention. With such strict config you would end up with some valid groups and some of them would have been split in an unexpected way. What would work, though, is some kind of user-specific list of prefixes that should be grouped, like At the same time I am afraid this wouldn't be a priority for core team. I would accept it if it was contributed, but personally I rather won't work on it. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the reply. I guess I will try to make a PR, and we'll see how it turns out. Take care. |
Beta Was this translation helpful? Give feedback.
-
I don't have that much experience with writing fixers (the ones that I did write are nothing to phone home about), so I think it might be better to give a suggestion for a feature:
PhpCsFixer\Fixer\Import\GroupImportFixer
by design only groups by the final part of the namespace, which is to say, it only groups files in the same directory.It would be nice from the readability standpoint to allow to control the index at which grouping is done, both in positive and negative direction. That way, we would have something like this:
['indent_index' => 0]
- no grouping, same asfalse
right now['indent_index' => 1]
- how it works withtrue
right now and how the default config should work for the sake of backwards compatibility, of course. An option (or a separate fixer) to keep each grouped import on separate lines, like in the image, would be nice as well['indent_index' => 2]
- how it works right now but one extra namespace index, probably too excessive for most use cases, will usually overlap with one of the following two['indent_index' => -1]
- would group all classes from the same vendor*, or group all by the first root namespace['indent_index' => -2]
- would group all classes from the same package*, or group all by the 2nd root namespace* assuming the package is regularly namespaced Vendor\Package, it works slightly differently for namespaces like
PhpCsFixer\
, as -2 option doesn't give the desired results.Beta Was this translation helpful? Give feedback.
All reactions