mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-26 20:10:09 +00:00
Sort relative imports by parent level descending (#856)
This commit is contained in:
parent
f8b49f308d
commit
7bd6db62d9
3 changed files with 29 additions and 0 deletions
4
resources/test/fixtures/isort/order_relative_imports_by_level.py
vendored
Normal file
4
resources/test/fixtures/isort/order_relative_imports_by_level.py
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
from .a import a
|
||||
from ..a import a
|
||||
from ..b import a
|
||||
from .b import a
|
|
@ -1,3 +1,4 @@
|
|||
use std::cmp::Reverse;
|
||||
use std::collections::{BTreeMap, BTreeSet};
|
||||
use std::path::PathBuf;
|
||||
|
||||
|
@ -381,6 +382,7 @@ fn sort_imports(block: ImportBlock) -> OrderedImportBlock {
|
|||
// Sort each `StmtKind::ImportFrom` by module key, breaking ties based on
|
||||
// members.
|
||||
(
|
||||
Reverse(import_from.level),
|
||||
import_from
|
||||
.module
|
||||
.as_ref()
|
||||
|
@ -477,6 +479,7 @@ mod tests {
|
|||
#[test_case(Path::new("leading_prefix.py"))]
|
||||
#[test_case(Path::new("no_reorder_within_section.py"))]
|
||||
#[test_case(Path::new("order_by_type.py"))]
|
||||
#[test_case(Path::new("order_relative_imports_by_level.py"))]
|
||||
#[test_case(Path::new("preserve_comment_order.py"))]
|
||||
#[test_case(Path::new("preserve_indentation.py"))]
|
||||
#[test_case(Path::new("reorder_within_section.py"))]
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
---
|
||||
source: src/isort/mod.rs
|
||||
expression: checks
|
||||
---
|
||||
- kind: UnsortedImports
|
||||
location:
|
||||
row: 1
|
||||
column: 0
|
||||
end_location:
|
||||
row: 5
|
||||
column: 0
|
||||
fix:
|
||||
patch:
|
||||
content: "from ..a import a\nfrom ..b import a\nfrom .a import a\nfrom .b import a\n"
|
||||
location:
|
||||
row: 1
|
||||
column: 0
|
||||
end_location:
|
||||
row: 5
|
||||
column: 0
|
||||
applied: false
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue