Repository: astral-sh/ruff
File: crates/ruff_linter/src/rules/flake8_import_conventions/settings.rs (Rust)

Code before:

pub fn default_aliases() -> FxHashMap<String, String> {
    CONVENTIONAL_ALIASES
        .iter()
        .map(|(k, v)| ((*k).to_string(), (*v).to_string()))
        .collect::<FxHashMap<_, _>>()
}

pub fn preview_aliases() -> FxHashMap<String, String> {
    PREVIEW_ALIASES
        .iter()
        .map(|(k, v)| ((*k).to_string(), (*v).to_string()))
        .collect::<FxHashMap<_, _>>()
}

pub fn preview_banned_aliases() -> FxHashMap<String, BannedAliases> {
    FxHashMap::from_iter([(
        "geopandas".to_string(),
        BannedAliases::from_iter(["gpd".to_string()]),
    )])
}

impl Settings {
    /// Merge preview aliases and banned aliases into the settings if preview mode is enabled.
    #[must_use]
    pub fn with_preview(mut self, preview_enabled: bool) -> Self {
        if preview_enabled {
            self.aliases.extend(preview_aliases());
            self.banned_aliases.extend(preview_banned_aliases());
        }
        self
    }
}

impl Default for Settings {
    fn default() -> Self {
        Self {
            aliases: default_aliases(),
            banned_aliases: FxHashMap::default(),
            banned_from: FxHashSet::default(),
        }
    }
}

impl Display for Settings {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        display_settings! {
            formatter = f,
            namespace = "linter.flake8_import_conventions",
            fields = [
                self.aliases | map,

Review comment (suggestion):
I think the way we usually handle this is by defining a method that takes a `preview` argument instead of `impl Default` (which can't take arguments). This is kind of the opposite since it was a stabilization PR, but you can see an example here: https://github.com/astral-sh/ruff/pull/12838/files#diff-0e4daa1a461406d9fd7af87b85ff4ecc89bd61f748d2b7cb24b88b25c7d5ba59

Possibly a better example: https://github.com/astral-sh/ruff/pull/15951

Code after:
    pub banned_from: FxHashSet<String>,
}

pub fn default_aliases(preview: PreviewMode) -> FxHashMap<String, String> {
    let mut aliases = CONVENTIONAL_ALIASES
        .iter()
        .map(|(k, v)| ((*k).to_string(), (*v).to_string()))
        .collect::<FxHashMap<_, _>>();

    if is_expanded_import_conventions_enabled(preview) {
        aliases.extend(
            PREVIEW_ALIASES
                .iter()
                .map(|(k, v)| ((*k).to_string(), (*v).to_string())),
        );
    }

    aliases
}

pub fn default_banned_aliases(preview: PreviewMode) -> FxHashMap<String, BannedAliases> {
    if is_expanded_import_conventions_enabled(preview) {
        FxHashMap::from_iter([(
            "geopandas".to_string(),
            BannedAliases::from_iter(["gpd".to_string()]),
        )])
    } else {
        FxHashMap::default()
    }
}

impl Settings {
    pub fn new(preview: PreviewMode) -> Self {
        Self {
            aliases: default_aliases(preview),
            banned_aliases: default_banned_aliases(preview),
            banned_from: FxHashSet::default(),
        }
    }
}

impl Default for Settings {
    fn default() -> Self {
        Self {
            aliases: default_aliases(PreviewMode::Disabled),
            banned_aliases: default_banned_aliases(PreviewMode::Disabled),
            banned_from: FxHashSet::default(),
        }
    }
}