Skip to content

package-qualified imports are sorted poorly #1048

@sellout

Description

@sellout

Ormolu ignores the package name when sorting imports.

import ElidedPackage
import "otherpackage" Baz
import "this" Bar
import "this" Foo
import "whatpackage" Meh

gets re-ordered by Ormolu to

import "this" Bar
import "otherpackage" Baz
import ElidedPackage
import "this" Foo
import "whatpackage" Meh

I think imports should be sorted by package name then module. Imports without package qualifiers can be sorted as if the package were "".

I think my ideal version would also separate out the special "this" package, rather than putting it among the “t”s. And maybe even include blank lines between the three groups (or perhaps just between "this" and the other imports, to indicate that "this" is handled specially:

import ElidedPackage

import "otherpackage" Baz
import "whatpackage" Meh

import "this" Bar
import "this" Foo

Metadata

Metadata

Assignees

No one assigned

    Labels

    styleNitpicking and things related to purely visual aspect for formatting.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions