ruff
c9931a54 - Implement isort's `default-section` setting (#10149)

Commit
1 year ago
Implement isort's `default-section` setting (#10149) ## Summary This fixes https://github.com/astral-sh/ruff/issues/7868. Support isort's `default-section` feature which allows any imports that match sections that are not in `section-order` to be mapped to a specifically named section. https://pycqa.github.io/isort/docs/configuration/options.html#default-section This has a few implications: - It is no longer required that all known sections are defined in `section-order`. - This is technically a bw-incompat change because currently if folks define custom groups, and do not define a `section-order`, the code used to add all known sections to `section-order` while emitting warnings. **However, when this happened, users would be seeing warnings so I do not think it should count as a bw-incompat change.** ## Test Plan - Added a new test. - Did not break any existing tests. Finally, I ran the following config against Pyramid's complex codebase that was previously using isort and this change worked there. ### pyramid's previous isort config https://github.com/Pylons/pyramid/blob/5f7e286b0629b0a5f1225fe51172cba77eb8fda1/pyproject.toml#L22-L37 ```toml [tool.isort] profile = "black" multi_line_output = 3 src_paths = ["src", "tests"] skip_glob = ["docs/*"] include_trailing_comma = true force_grid_wrap = false combine_as_imports = true line_length = 79 force_sort_within_sections = true no_lines_before = "THIRDPARTY" sections = "FUTURE,THIRDPARTY,FIRSTPARTY,LOCALFOLDER" default_section = "THIRDPARTY" known_first_party = "pyramid" ``` ### tested with ruff isort config ```toml [tool.ruff.lint.isort] case-sensitive = true combine-as-imports = true force-sort-within-sections = true section-order = [ "future", "third-party", "first-party", "local-folder", ] default-section = "third-party" known-first-party = [ "pyramid", ] ```
Author
Parents
Loading