Skip to content

reorder-imports should have option to preserve import groups #1205

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
fuine opened this issue Nov 1, 2016 · 3 comments · Fixed by #1562
Closed

reorder-imports should have option to preserve import groups #1205

fuine opened this issue Nov 1, 2016 · 3 comments · Fixed by #1562

Comments

@fuine
Copy link

fuine commented Nov 1, 2016

Currently (version 0.6.2) rustfmt will change this:

use a;
use x;
use b;

use std::io;

to

use a;
use b;

use std::io;
use x;

By group i mean consecutive lines of imports. Groups are divided by empty newlines. I write my imports such that imports from the crate i'm working on are in one group and imports from other crates/std get put in different group. Rustfmt mixes them, which defeats the purpose of grouping. On the other hand i would like to have both groups sorted within themselves. Is there a way to achieve that with current version of rustfmt and if not could this be considered?
For the example above i'd like rustfmt to change it like so:

use a;
use b;
use x;

use std::io;
@hmvp
Copy link

hmvp commented Dec 1, 2016

I'd like this as well. I typically sort my imports in three groups like this:

use std::cmp;
use std::fmt;

use byteorder;
use socketcan;

use same_crate_a;
use same_crate_b;

At least the formatters I used for Python and Java do similar things

@ssokolow
Copy link

Seconded. I also picked up that habit in the Python world and I currently keep my imports sorted manually because I value the groups more than the convenience of rustfmt.

@ebkalderon
Copy link

Issue #1302 is somewhat related to this one.

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 a pull request may close this issue.

4 participants