Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ordering for force-sort-within-sections #8665

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import encodings
from datetime import timezone as tz
from datetime import timedelta
import datetime as dt
import datetime
1 change: 1 addition & 0 deletions crates/ruff_linter/src/rules/isort/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,7 @@ mod tests {
}

#[test_case(Path::new("force_sort_within_sections.py"))]
#[test_case(Path::new("force_sort_within_sections_with_as_names.py"))]
fn force_sort_within_sections(path: &Path) -> Result<()> {
let snapshot = format!("force_sort_within_sections_{}", path.to_string_lossy());
let mut diagnostics = test_path(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
source: crates/ruff_linter/src/rules/isort/mod.rs
---
force_sort_within_sections_with_as_names.py:1:1: I001 [*] Import block is un-sorted or un-formatted
|
1 | / import encodings
2 | | from datetime import timezone as tz
3 | | from datetime import timedelta
4 | | import datetime as dt
5 | | import datetime
|
= help: Organize imports

ℹ Safe fix
1 |+import datetime
2 |+import datetime as dt
3 |+from datetime import timedelta
4 |+from datetime import timezone as tz
1 5 | import encodings
2 |-from datetime import timezone as tz
3 |-from datetime import timedelta
4 |-import datetime as dt
5 |-import datetime


4 changes: 2 additions & 2 deletions crates/ruff_linter/src/rules/isort/sorting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ pub(crate) struct ModuleKey<'a> {
force_to_top: Option<bool>,
maybe_lowercase_name: Option<NatOrdStr<'a>>,
module_name: Option<NatOrdStr<'a>>,
asname: Option<NatOrdStr<'a>>,
first_alias: Option<MemberKey<'a>>,
asname: Option<NatOrdStr<'a>>,
}

impl<'a> ModuleKey<'a> {
Expand Down Expand Up @@ -110,8 +110,8 @@ impl<'a> ModuleKey<'a> {
force_to_top,
maybe_lowercase_name,
module_name,
asname,
first_alias,
asname,
}
}
}
Expand Down
Loading