Skip to content

Commit

Permalink
Preserve star-handling special-casing for force-single-line (#4129)
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh authored Apr 27, 2023
1 parent 17db2e2 commit 3c9f5e2
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@
a, # comment 7
b, # comment 8
)

# comment 9
from baz import * # comment 10
3 changes: 2 additions & 1 deletion crates/ruff/src/rules/isort/normalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ pub fn normalize_imports<'a>(
} => {
// Whether to track each member of the import as a separate entry.
let isolate_aliases = force_single_line
&& module.map_or(true, |module| !single_line_exclusions.contains(module));
&& module.map_or(true, |module| !single_line_exclusions.contains(module))
&& !names.first().map_or(false, |alias| alias.name == "*");

// Insert comments on the statement itself.
if isolate_aliases {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ force_single_line.py:1:1: I001 [*] Import block is un-sorted or un-formatted
22 | | a, # comment 7
23 | | b, # comment 8
24 | | )
25 | |
26 | | # comment 9
27 | | from baz import * # comment 10
|
= help: Organize imports

Expand All @@ -44,35 +47,39 @@ force_single_line.py:1:1: I001 [*] Import block is un-sorted or un-formatted
8 |+from logging.handlers import FileHandler, StreamHandler
9 |+from os import path, uname
9 10 |
10 |-# comment 1
11 |-from third_party import lib1, lib2, \
12 |- lib3, lib7, lib5, lib6
13 |-# comment 2
14 |-from third_party import lib4
11 |+# comment 6
12 |+from bar import a # comment 7
13 |+from bar import b # comment 8
14 |+from foo import bar # comment 3
15 |+from foo2 import bar2 # comment 4
16 |+from foo3 import bar3 # comment 5
17 |+from foo3 import baz3 # comment 5
18 |+
10 19 | # comment 1
11 |-from third_party import lib1, lib2, \
12 |- lib3, lib7, lib5, lib6
20 |+from third_party import lib1
21 |+from third_party import lib2
22 |+from third_party import lib3
23 |+
13 24 | # comment 2
14 25 | from third_party import lib4
15 |-
16 |-from foo import bar # comment 3
17 |-from foo2 import bar2 # comment 4
15 14 |
15 |+# comment 9
16 |+from baz import * # comment 10
16 17 | from foo import bar # comment 3
17 18 | from foo2 import bar2 # comment 4
18 |-from foo3 import bar3, baz3 # comment 5
19 |-
19 |+from foo3 import bar3 # comment 5
20 |+from foo3 import baz3 # comment 5
19 21 |
20 |-# comment 6
21 |-from bar import (
22 |- a, # comment 7
23 |- b, # comment 8
24 |-)
26 |+from third_party import lib5
27 |+from third_party import lib6
28 |+from third_party import lib7
22 |+# comment 1
23 |+from third_party import lib1
24 |+from third_party import lib2
25 |+from third_party import lib3
25 26 |
26 |-# comment 9
27 |-from baz import * # comment 10
27 |+# comment 2
28 |+from third_party import lib4
29 |+from third_party import lib5
30 |+from third_party import lib6
31 |+from third_party import lib7


0 comments on commit 3c9f5e2

Please sign in to comment.