Skip to content

[RFC] Merge imports by default #140

Open
@gnzlbg

Description

@gnzlbg

Merging imports by default makes imports clearer, e.g.,

use rocket::{
    Request, Response,
    request::{self, Form},
    response::{Flash, Redirect}
};
use rocket_contrib::JsonValue;

use strum::EnumMessage;

is visually easier to parse than

use rocket::Request;
use rocket::Response;
use rocket::request;
use rocket::request::Form;
use rocket::response::Flash;
use rocket::response::Redirect;
use rocket_contrib::JsonValue;

use strum::EnumMessage;

since the { } in grouped imports make scoping clearer, as opposed to having to parse whether there are differences in lines, like in

use rocket::response::Redirect;
use rocket_contrib::JsonValue;

where there is a common prefix.

Tools can optionally offer an option to disable merging imports by default.

This does not change the rules with respect to grouping imports separated by empty lines (this is still not done), that is, this:

use rocket::Request;
use rocket::Response;

use rocket::request;
use rocket::request::Form;

continues to be merged as

use rocket::{Request, Response};

use rocket::request::{self, Form};

Prior art

rustfmt has a merge_imports option that does this. There are some bugs open for this feature that would need to be closed before stabilization.

Prior discussions

This comment in #24 proposed not merging imports by default, without rationale for that decision.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions