ruff
d056a9fa - [`isort`] support for configurable import section heading comments (#23151)

Commit
107 days ago
[`isort`] support for configurable import section heading comments (#23151) <!-- Thank you for contributing to Ruff/ty! To help us out with reviewing, please consider the following: - Does this pull request include a summary of the change? (See below.) - Does this pull request include a descriptive title? (Please prefix with `[ty]` for ty pull requests.) - Does this pull request include references to any relevant issues? --> ## Summary fixes #6371 - `settings.rs` - Added import_headings: FxHashMap<ImportSection, String> field to Settings struct with default and display support - `options.rs` - Added import_heading configuration option with #[option] metadata, documentation, and TOML table syntax. Added validation for unknown sections and mapping to Settings - `mod.rs` - Core logic in format_import_block: - Collects all configured heading values as "# {heading}" strings - Strips matching heading comments from ALL imports in each section (handles reordering) - Inserts heading comments above each section after blank line logic - `organize_imports.rs` - Extended fix range backward to include heading comment lines above the first import, preventing duplication on fix application ## Test Plan Test Coverage (9 new tests, 156 total passing) ``` cargo test -p ruff_linter -- isort::tests cargo test -p ruff_linter -- isort::tests::import_heading ``` | Test | Scenario | |-------------------------------------------|------------------------------------------------------| | import_heading.py | Basic unsorted imports get headings added | | import_heading_already_present.py | Existing headings stripped and re-added correctly | | import_heading_already_correct.py | Properly sorted+headed imports produce NO diagnostic | | import_heading_unsorted.py | Completely unsorted imports get sorted with headings | | import_heading_with_no_lines_before.py | Interaction with no_lines_before setting | | import_heading_partial.py | Headings configured for only some sections | | import_heading_wrong_heading.py | Non-matching comments preserved as regular comments | | import_heading_single_section.py | Only one section present gets its heading | | import_heading_force_sort_within_sections.py | Works with force_sort_within_sections | --------- Co-authored-by: Brent Westbrook <36778786+ntBre@users.noreply.github.com> Co-authored-by: Amethyst Reese <amethyst@n7.gg>
Parents
Loading