Skip to content

define/enforce import ordering #1211

@zachschuermann

Description

@zachschuermann

Currently cargo fmt will happily format imports in contiguous blocks alphabetically, but we generally prefer having a few blocks grouping {std, third-party, internal crates, this crate} in that order.

Example:

// GOOD
use std::sync::Arc;

use itertools::Itertools;
use serde::Deserialize;

use internal_crate::Something;

use crate::log_segment::ListedLogFiles;
use crate::Engine;

// BAD (all squished - and then fmt will actually re-order them to alphabetize)
use std::sync::Arc;
use itertools::Itertools;
use serde::Deserialize;
use internal_crate::Something;
use crate::log_segment::ListedLogFiles;
use crate::Engine;

I've looked into some solutions here but unfortunately adding the following to rustfmt.toml is only available on nightly and does a bunch of deeply nested imports which we generally don't like:

imports_granularity = "Crate"
group_imports = "StdExternalCrate"
imports_layout = "Mixed"

Metadata

Metadata

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