diff --git a/pyproject.toml b/pyproject.toml index f83ea46aeb..e1a49958d1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" diff --git a/resources/test/fixtures/isort/comments.py b/resources/test/fixtures/isort/comments.py index e3f0460699..ac9154e506 100644 --- a/resources/test/fixtures/isort/comments.py +++ b/resources/test/fixtures/isort/comments.py @@ -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 diff --git a/src/isort/format.rs b/src/isort/format.rs index 504f7cbe77..80a15402ea 100644 --- a/src/isort/format.rs +++ b/src/isort/format.rs @@ -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())) diff --git a/src/isort/snapshots/ruff__isort__tests__comments.py.snap b/src/isort/snapshots/ruff__isort__tests__comments.py.snap index 3eef679acd..5042899d74 100644 --- a/src/isort/snapshots/ruff__isort__tests__comments.py.snap +++ b/src/isort/snapshots/ruff__isort__tests__comments.py.snap @@ -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: ~