tweag / ormolu

A formatter for Haskell source code
https://ormolu-live.tweag.io
Other
944 stars 83 forks source link

package-qualified imports are sorted poorly #1048

Closed sellout closed 11 months ago

sellout commented 1 year ago

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
amesgen commented 1 year ago

This was changed in #905 (grouping, but not with newlines). Can you try using Ormolu >=0.5.1.0? There, the output of your snippet should be

import ElidedPackage
import "otherpackage" Baz
import "this" Bar
import "this" Foo
import "whatpackage" Meh
sellout commented 1 year ago

Ah, sorry. This is fine for me, then.

I do think separating out "this" would still be good (because it’s not actually a package name), but the blank lines I can take or leave.

amesgen commented 1 year ago

I do think separating out "this" would still be good (because it’s not actually a package name)

Yes, I think that is a good point :+1:

amesgen commented 11 months ago

Reopening in order to let #1057 close it again :smile: