Context
While upgrading perfectionist to 0.0.0-rc.18 (which introduces the
import_grouping rule), this project adopted the single_group style:
["perfectionist::import_grouping"]
style = "single_group"
The problem
single_group requires that no blank line sit between any two statements
of an import run. However, this project has a long-standing convention
(documented in CONTRIBUTING.md) of keeping platform/feature-gated
imports in their own trailing block, separated by a blank line:
use super::size::Bytes;
use std::fs::Metadata;
#[cfg(unix)]
use super::size::Blocks;
#[cfg(unix)]
use std::os::unix::prelude::MetadataExt;
This separation is desirable: the unconditional imports and the
#[cfg]-gated ones are conceptually distinct, and the blank line makes
the boundary obvious. The grouped style already models this through its
cfg_block_handling = "trailing" knob, but single_group has no
equivalent, so it flags every such file.
Suggestion
single_group should treat a run of #[cfg(...)]-gated imports as an
allowed trailing group, the same way grouped does with
cfg_block_handling = "trailing". A dedicated knob (for example
cfg_block_handling on single_group, defaulting to trailing) would
let a project opt in or out.
Workaround in this repository
Until this is addressed upstream, the affected files carry a
module-level suppression:
#![expect(
perfectionist::import_grouping,
reason = "single_group cannot keep #[cfg]-gated imports in their own trailing group; see issue #436"
)]
This issue tracks removing those suppressions once single_group can
express the trailing #[cfg] group.
Context
While upgrading
perfectionistto0.0.0-rc.18(which introduces theimport_groupingrule), this project adopted thesingle_groupstyle:The problem
single_grouprequires that no blank line sit between any two statementsof an import run. However, this project has a long-standing convention
(documented in
CONTRIBUTING.md) of keeping platform/feature-gatedimports in their own trailing block, separated by a blank line:
This separation is desirable: the unconditional imports and the
#[cfg]-gated ones are conceptually distinct, and the blank line makesthe boundary obvious. The
groupedstyle already models this through itscfg_block_handling = "trailing"knob, butsingle_grouphas noequivalent, so it flags every such file.
Suggestion
single_groupshould treat a run of#[cfg(...)]-gated imports as anallowed trailing group, the same way
groupeddoes withcfg_block_handling = "trailing". A dedicated knob (for examplecfg_block_handlingonsingle_group, defaulting totrailing) wouldlet a project opt in or out.
Workaround in this repository
Until this is addressed upstream, the affected files carry a
module-level suppression:
This issue tracks removing those suppressions once
single_groupcanexpress the trailing
#[cfg]group.