mirror of https://github.com/astral-sh/ruff
Avoid merging import from statements with inline comments (#1562)
This commit is contained in:
parent
e9be5fc7be
commit
6d5aa344a1
|
|
@ -40,11 +40,5 @@ strip = true
|
|||
[tool.ruff]
|
||||
line-length = 88
|
||||
|
||||
[tool.ruff.isort]
|
||||
force-wrap-aliases = true
|
||||
combine-as-imports = true
|
||||
force-single-line = true
|
||||
single-line-exclusions = ["os", "logging.handlers"]
|
||||
|
||||
[tool.ruff.pydocstyle]
|
||||
convention = "google"
|
||||
|
|
|
|||
|
|
@ -26,3 +26,8 @@ from A import (
|
|||
|
||||
from D import a_long_name_to_force_multiple_lines # Comment 12
|
||||
from D import another_long_name_to_force_multiple_lines # Comment 13
|
||||
|
||||
from E import a # Comment 1
|
||||
|
||||
from F import a # Comment 1
|
||||
from F import b
|
||||
|
|
|
|||
|
|
@ -61,17 +61,12 @@ pub fn format_import_from(
|
|||
return single_line;
|
||||
}
|
||||
|
||||
// We can only inline if: (1) none of the aliases have atop comments, and (3)
|
||||
// only the last alias (if any) has inline comments.
|
||||
// We can only inline if none of the aliases have atop or inline comments.
|
||||
if !trailing_comma
|
||||
&& aliases
|
||||
.iter()
|
||||
.all(|(_, CommentSet { atop, .. })| atop.is_empty())
|
||||
&& aliases
|
||||
.iter()
|
||||
.rev()
|
||||
.skip(1)
|
||||
.all(|(_, CommentSet { inline, .. })| inline.is_empty())
|
||||
&& (aliases.len() == 1
|
||||
|| aliases
|
||||
.iter()
|
||||
.all(|(_, CommentSet { atop, inline })| atop.is_empty() && inline.is_empty()))
|
||||
&& (!force_wrap_aliases
|
||||
|| aliases.len() == 1
|
||||
|| aliases.iter().all(|(alias, _)| alias.asname.is_none()))
|
||||
|
|
|
|||
|
|
@ -7,15 +7,15 @@ expression: checks
|
|||
row: 3
|
||||
column: 0
|
||||
end_location:
|
||||
row: 29
|
||||
row: 34
|
||||
column: 0
|
||||
fix:
|
||||
content: "import B # Comment 4\n\n# Comment 3a\n# Comment 3b\nimport C\nimport D\n\n# Comment 5\n# Comment 6\nfrom A import (\n a, # Comment 7 # Comment 9\n b, # Comment 10\n c, # Comment 8 # Comment 11\n)\nfrom D import (\n a_long_name_to_force_multiple_lines, # Comment 12\n another_long_name_to_force_multiple_lines, # Comment 13\n)\n"
|
||||
content: "import B # Comment 4\n\n# Comment 3a\n# Comment 3b\nimport C\nimport D\n\n# Comment 5\n# Comment 6\nfrom A import (\n a, # Comment 7 # Comment 9\n b, # Comment 10\n c, # Comment 8 # Comment 11\n)\nfrom D import (\n a_long_name_to_force_multiple_lines, # Comment 12\n another_long_name_to_force_multiple_lines, # Comment 13\n)\nfrom E import a # Comment 1\nfrom F import (\n a, # Comment 1\n b,\n)\n"
|
||||
location:
|
||||
row: 3
|
||||
column: 0
|
||||
end_location:
|
||||
row: 29
|
||||
row: 34
|
||||
column: 0
|
||||
parent: ~
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue