Skip to content

Include as-alias in blink OrderedImports sort key - #214

Merged
TomasVotruba merged 2 commits into
mainfrom
tv/blink-ordered-imports-alias-key
Oct 21, 2026
Merged

TomasVotruba merged 2 commits into
mainfrom
tv/blink-ordered-imports-alias-key

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

blink's OrderedImports built its alphabetical sort key from the imported path only, breaking at as. PHP-CS-Fixer's OrderedImportsFixer includes the as <alias> suffix in the key (its namespace string, with \ mapped to a separator).

So for two imports of the same class, one aliased:

use Mautic\LeadBundle\Entity\Lead as TheLead;
use Mautic\LeadBundle\Entity\Lead;

both reduced to the same key in blink, a stable sort kept their order, and blink skipped a reorder that PHP applies. PHP sorts the plain import before the aliased one (its key is a prefix of the aliased key).

Fix: the sort key now includes the as <alias> suffix. Backslashes and whitespace both map to \x00 as the shared separator, so \ and the space before as sort before any identifier character, matching PHP's space-separator comparison. For imports without an alias the key is byte-identical to before, so only aliased imports change.

Covered by TestOrderedImportsAliasInSortKey.

@TomasVotruba
TomasVotruba merged commit 1fc33ab into main Oct 21, 2026
20 checks passed
@TomasVotruba
TomasVotruba deleted the tv/blink-ordered-imports-alias-key branch October 21, 2026 20:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant