From 924fd616273c028ea08a255ed1a4778b950d4712 Mon Sep 17 00:00:00 2001 From: Dan Date: Thu, 13 Nov 2025 21:11:42 -0500 Subject: [PATCH] Fix preview snaps; cargo clippy --- ...t__requires_python_extend_from_shared_config.snap | 6 +----- .../cli__lint__requires_python_no_tool.snap | 6 +----- ...uires_python_no_tool_target_version_override.snap | 6 +----- ...__lint__requires_python_pyproject_toml_above.snap | 6 +----- ...quires_python_pyproject_toml_above_with_tool.snap | 6 +----- ...cli__lint__requires_python_ruff_toml_above-2.snap | 6 +----- .../cli__lint__requires_python_ruff_toml_above.snap | 6 +----- ...requires_python_ruff_toml_no_target_fallback.snap | 6 +----- .../show_settings__display_default_settings.snap | 6 +----- .../src/rules/flake8_import_conventions/settings.rs | 12 ++++++++++++ crates/ruff_workspace/src/configuration.rs | 6 +++++- crates/ruff_workspace/src/options.rs | 4 +--- 12 files changed, 27 insertions(+), 49 deletions(-) diff --git a/crates/ruff/tests/cli/snapshots/cli__lint__requires_python_extend_from_shared_config.snap b/crates/ruff/tests/cli/snapshots/cli__lint__requires_python_extend_from_shared_config.snap index 7a67abe52e..cad465dc4e 100644 --- a/crates/ruff/tests/cli/snapshots/cli__lint__requires_python_extend_from_shared_config.snap +++ b/crates/ruff/tests/cli/snapshots/cli__lint__requires_python_extend_from_shared_config.snap @@ -142,18 +142,14 @@ linter.flake8_import_conventions.aliases = { pandas = pd, panel = pn, plotly.express = px, - plotly.graph_objects = go, polars = pl, pyarrow = pa, seaborn = sns, - statsmodels.api = sm, tensorflow = tf, tkinter = tk, xml.etree.ElementTree = ET, } -linter.flake8_import_conventions.banned_aliases = { - geopandas = [gpd], -} +linter.flake8_import_conventions.banned_aliases = {} linter.flake8_import_conventions.banned_from = [] linter.flake8_pytest_style.fixture_parentheses = false linter.flake8_pytest_style.parametrize_names_type = tuple diff --git a/crates/ruff/tests/cli/snapshots/cli__lint__requires_python_no_tool.snap b/crates/ruff/tests/cli/snapshots/cli__lint__requires_python_no_tool.snap index 455f58bec9..47b6f47c1a 100644 --- a/crates/ruff/tests/cli/snapshots/cli__lint__requires_python_no_tool.snap +++ b/crates/ruff/tests/cli/snapshots/cli__lint__requires_python_no_tool.snap @@ -144,18 +144,14 @@ linter.flake8_import_conventions.aliases = { pandas = pd, panel = pn, plotly.express = px, - plotly.graph_objects = go, polars = pl, pyarrow = pa, seaborn = sns, - statsmodels.api = sm, tensorflow = tf, tkinter = tk, xml.etree.ElementTree = ET, } -linter.flake8_import_conventions.banned_aliases = { - geopandas = [gpd], -} +linter.flake8_import_conventions.banned_aliases = {} linter.flake8_import_conventions.banned_from = [] linter.flake8_pytest_style.fixture_parentheses = false linter.flake8_pytest_style.parametrize_names_type = tuple diff --git a/crates/ruff/tests/cli/snapshots/cli__lint__requires_python_no_tool_target_version_override.snap b/crates/ruff/tests/cli/snapshots/cli__lint__requires_python_no_tool_target_version_override.snap index 00ff41dc62..4de849c6a1 100644 --- a/crates/ruff/tests/cli/snapshots/cli__lint__requires_python_no_tool_target_version_override.snap +++ b/crates/ruff/tests/cli/snapshots/cli__lint__requires_python_no_tool_target_version_override.snap @@ -146,18 +146,14 @@ linter.flake8_import_conventions.aliases = { pandas = pd, panel = pn, plotly.express = px, - plotly.graph_objects = go, polars = pl, pyarrow = pa, seaborn = sns, - statsmodels.api = sm, tensorflow = tf, tkinter = tk, xml.etree.ElementTree = ET, } -linter.flake8_import_conventions.banned_aliases = { - geopandas = [gpd], -} +linter.flake8_import_conventions.banned_aliases = {} linter.flake8_import_conventions.banned_from = [] linter.flake8_pytest_style.fixture_parentheses = false linter.flake8_pytest_style.parametrize_names_type = tuple diff --git a/crates/ruff/tests/cli/snapshots/cli__lint__requires_python_pyproject_toml_above.snap b/crates/ruff/tests/cli/snapshots/cli__lint__requires_python_pyproject_toml_above.snap index 5752bc3296..c7f04bcbe2 100644 --- a/crates/ruff/tests/cli/snapshots/cli__lint__requires_python_pyproject_toml_above.snap +++ b/crates/ruff/tests/cli/snapshots/cli__lint__requires_python_pyproject_toml_above.snap @@ -143,18 +143,14 @@ linter.flake8_import_conventions.aliases = { pandas = pd, panel = pn, plotly.express = px, - plotly.graph_objects = go, polars = pl, pyarrow = pa, seaborn = sns, - statsmodels.api = sm, tensorflow = tf, tkinter = tk, xml.etree.ElementTree = ET, } -linter.flake8_import_conventions.banned_aliases = { - geopandas = [gpd], -} +linter.flake8_import_conventions.banned_aliases = {} linter.flake8_import_conventions.banned_from = [] linter.flake8_pytest_style.fixture_parentheses = false linter.flake8_pytest_style.parametrize_names_type = tuple diff --git a/crates/ruff/tests/cli/snapshots/cli__lint__requires_python_pyproject_toml_above_with_tool.snap b/crates/ruff/tests/cli/snapshots/cli__lint__requires_python_pyproject_toml_above_with_tool.snap index 76b34de492..66e3dd06ba 100644 --- a/crates/ruff/tests/cli/snapshots/cli__lint__requires_python_pyproject_toml_above_with_tool.snap +++ b/crates/ruff/tests/cli/snapshots/cli__lint__requires_python_pyproject_toml_above_with_tool.snap @@ -143,18 +143,14 @@ linter.flake8_import_conventions.aliases = { pandas = pd, panel = pn, plotly.express = px, - plotly.graph_objects = go, polars = pl, pyarrow = pa, seaborn = sns, - statsmodels.api = sm, tensorflow = tf, tkinter = tk, xml.etree.ElementTree = ET, } -linter.flake8_import_conventions.banned_aliases = { - geopandas = [gpd], -} +linter.flake8_import_conventions.banned_aliases = {} linter.flake8_import_conventions.banned_from = [] linter.flake8_pytest_style.fixture_parentheses = false linter.flake8_pytest_style.parametrize_names_type = tuple diff --git a/crates/ruff/tests/cli/snapshots/cli__lint__requires_python_ruff_toml_above-2.snap b/crates/ruff/tests/cli/snapshots/cli__lint__requires_python_ruff_toml_above-2.snap index a40d8c27e9..da3eb66afc 100644 --- a/crates/ruff/tests/cli/snapshots/cli__lint__requires_python_ruff_toml_above-2.snap +++ b/crates/ruff/tests/cli/snapshots/cli__lint__requires_python_ruff_toml_above-2.snap @@ -142,18 +142,14 @@ linter.flake8_import_conventions.aliases = { pandas = pd, panel = pn, plotly.express = px, - plotly.graph_objects = go, polars = pl, pyarrow = pa, seaborn = sns, - statsmodels.api = sm, tensorflow = tf, tkinter = tk, xml.etree.ElementTree = ET, } -linter.flake8_import_conventions.banned_aliases = { - geopandas = [gpd], -} +linter.flake8_import_conventions.banned_aliases = {} linter.flake8_import_conventions.banned_from = [] linter.flake8_pytest_style.fixture_parentheses = false linter.flake8_pytest_style.parametrize_names_type = tuple diff --git a/crates/ruff/tests/cli/snapshots/cli__lint__requires_python_ruff_toml_above.snap b/crates/ruff/tests/cli/snapshots/cli__lint__requires_python_ruff_toml_above.snap index 6c23d8774f..e9ca7bd400 100644 --- a/crates/ruff/tests/cli/snapshots/cli__lint__requires_python_ruff_toml_above.snap +++ b/crates/ruff/tests/cli/snapshots/cli__lint__requires_python_ruff_toml_above.snap @@ -142,18 +142,14 @@ linter.flake8_import_conventions.aliases = { pandas = pd, panel = pn, plotly.express = px, - plotly.graph_objects = go, polars = pl, pyarrow = pa, seaborn = sns, - statsmodels.api = sm, tensorflow = tf, tkinter = tk, xml.etree.ElementTree = ET, } -linter.flake8_import_conventions.banned_aliases = { - geopandas = [gpd], -} +linter.flake8_import_conventions.banned_aliases = {} linter.flake8_import_conventions.banned_from = [] linter.flake8_pytest_style.fixture_parentheses = false linter.flake8_pytest_style.parametrize_names_type = tuple diff --git a/crates/ruff/tests/cli/snapshots/cli__lint__requires_python_ruff_toml_no_target_fallback.snap b/crates/ruff/tests/cli/snapshots/cli__lint__requires_python_ruff_toml_no_target_fallback.snap index 19207ecaf4..350ca02474 100644 --- a/crates/ruff/tests/cli/snapshots/cli__lint__requires_python_ruff_toml_no_target_fallback.snap +++ b/crates/ruff/tests/cli/snapshots/cli__lint__requires_python_ruff_toml_no_target_fallback.snap @@ -142,18 +142,14 @@ linter.flake8_import_conventions.aliases = { pandas = pd, panel = pn, plotly.express = px, - plotly.graph_objects = go, polars = pl, pyarrow = pa, seaborn = sns, - statsmodels.api = sm, tensorflow = tf, tkinter = tk, xml.etree.ElementTree = ET, } -linter.flake8_import_conventions.banned_aliases = { - geopandas = [gpd], -} +linter.flake8_import_conventions.banned_aliases = {} linter.flake8_import_conventions.banned_from = [] linter.flake8_pytest_style.fixture_parentheses = false linter.flake8_pytest_style.parametrize_names_type = tuple diff --git a/crates/ruff/tests/snapshots/show_settings__display_default_settings.snap b/crates/ruff/tests/snapshots/show_settings__display_default_settings.snap index 04fdec5c5e..28a6607816 100644 --- a/crates/ruff/tests/snapshots/show_settings__display_default_settings.snap +++ b/crates/ruff/tests/snapshots/show_settings__display_default_settings.snap @@ -255,18 +255,14 @@ linter.flake8_import_conventions.aliases = { pandas = pd, panel = pn, plotly.express = px, - plotly.graph_objects = go, polars = pl, pyarrow = pa, seaborn = sns, - statsmodels.api = sm, tensorflow = tf, tkinter = tk, xml.etree.ElementTree = ET, } -linter.flake8_import_conventions.banned_aliases = { - geopandas = [gpd], -} +linter.flake8_import_conventions.banned_aliases = {} linter.flake8_import_conventions.banned_from = [] linter.flake8_pytest_style.fixture_parentheses = false linter.flake8_pytest_style.parametrize_names_type = tuple diff --git a/crates/ruff_linter/src/rules/flake8_import_conventions/settings.rs b/crates/ruff_linter/src/rules/flake8_import_conventions/settings.rs index 53023c5e55..1cf69e5e53 100644 --- a/crates/ruff_linter/src/rules/flake8_import_conventions/settings.rs +++ b/crates/ruff_linter/src/rules/flake8_import_conventions/settings.rs @@ -90,6 +90,18 @@ pub fn preview_banned_aliases() -> FxHashMap { )]) } +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 { diff --git a/crates/ruff_workspace/src/configuration.rs b/crates/ruff_workspace/src/configuration.rs index 8ca5350d11..0bf9a50a48 100644 --- a/crates/ruff_workspace/src/configuration.rs +++ b/crates/ruff_workspace/src/configuration.rs @@ -247,12 +247,16 @@ impl Configuration { .map(IsortOptions::try_into_settings) .transpose()? .unwrap_or_default(); - let flake8_import_conventions = lint + let mut flake8_import_conventions = lint .flake8_import_conventions .map(Flake8ImportConventionsOptions::try_into_settings) .transpose()? .unwrap_or_default(); + // Merge preview aliases and banned aliases when preview mode is enabled + flake8_import_conventions = + flake8_import_conventions.with_preview(matches!(lint_preview, PreviewMode::Enabled)); + conflicting_import_settings(&isort, &flake8_import_conventions)?; let future_annotations = lint.future_annotations.unwrap_or_default(); diff --git a/crates/ruff_workspace/src/options.rs b/crates/ruff_workspace/src/options.rs index d90641cd30..e5205b3539 100644 --- a/crates/ruff_workspace/src/options.rs +++ b/crates/ruff_workspace/src/options.rs @@ -1685,9 +1685,7 @@ impl Flake8ImportConventionsOptions { Ok(flake8_import_conventions::settings::Settings { aliases: normalized_aliases, - banned_aliases: self - .banned_aliases - .unwrap_or_else(FxHashMap::default), + banned_aliases: self.banned_aliases.unwrap_or_default(), banned_from: self.banned_from.unwrap_or_default(), }) }