ruff
46f71fbf - [`flake8-import-conventions`] Add missing conventions from upstream (`ICN001`, `ICN002`) (#21373)

Commit
1 day ago
[`flake8-import-conventions`] Add missing conventions from upstream (`ICN001`, `ICN002`) (#21373) ## Summary Adds missing import conventions from upstream flake8-import-conventions plugin. Specifically: - `ICN001`: Enforces `plotly.graph_objects` → `go` and `statsmodels.api` → `sm` - `ICN002`: Bans `geopandas` → `gpd` alias Fixes #21300 ## Problem Analysis Ruff's `ICN001` (unconventional-import-alias) and `ICN002` (banned-import-alias) rules were missing some conventions enforced by the upstream [flake8-import-conventions](https://github.com/joaopalmeiro/flake8-import-conventions) plugin: 1. **ICN001 missing conventions:** - `plotly.graph_objects` should be imported as `go` (IC008 in upstream) - `statsmodels.api` should be imported as `sm` (IC010 in upstream) 2. **ICN002 missing convention:** - `geopandas` should not be imported as `gpd` (IC002 in upstream) The root cause was that these conventions were not included in Ruff's default configuration. The `CONVENTIONAL_ALIASES` constant was missing the two ICN001 entries, and there was no default banned aliases configuration for ICN002. ## Approach 1. **Added missing ICN001 conventions:** - Added `("plotly.graph_objects", "go")` and `("statsmodels.api", "sm")` to `CONVENTIONAL_ALIASES` in `settings.rs` - Updated the default option string in `options.rs` to include these new aliases 2. **Added default banned aliases for ICN002:** - Created `default_banned_aliases()` function returning `geopandas` → `["gpd"]` - Updated `Settings::default()` to use `default_banned_aliases()` - Updated `try_into_settings()` in `options.rs` to use `default_banned_aliases()` when `banned_aliases` is None - Updated the default option string for `banned_aliases` in `options.rs` 3. **Added comprehensive tests:** - Created `missing_conventions.py` test fixture with cases for all three new conventions - Added `missing_conventions` test in `mod.rs` to verify the new conventions work correctly ## Test Plan Added new snapshot test `missing_conventions` that verifies: - ICN001 correctly flags `plotly.graph_objects` without alias and requires `go` - ICN001 correctly flags `statsmodels.api` without alias and requires `sm` - ICN002 correctly flags `geopandas as gpd` as banned - All existing tests continue to pass (10/10 tests passing) The fix has been manually verified to match the behavior of upstream flake8-import-conventions. --------- Co-authored-by: Brent Westbrook <brentrwestbrook@gmail.com>
Author
Parents
Loading