Skip to content

Commit

Permalink
Fixed #1295: doesnt work with .
Browse files Browse the repository at this point in the history
  • Loading branch information
timothycrosley committed Jul 8, 2020
1 parent 65e0a3f commit d4ce124
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ NOTE: isort follows the [semver](https://semver.org/) versioning standard.
- Fixed #1297: Usage of `--add-imports` alongside `--check` is broken.
- Fixed #1289: Stream usage no longer auto picking up config file from current working directory.
- Fixed #1296: Force_single_line setting removes immediately following comment line.
- Fixed #1295: `ensure_newline_before_comments` doesnt work with `force_sort_within_sections`.

### 5.0.4 July 6, 2020
- Fixed #1264: a regression with comment handling and `force_sort_within_sections` config option
Expand Down
6 changes: 5 additions & 1 deletion isort/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,11 @@ def sorted_imports(
# uncollapse comments
section_output = []
for line in new_section_output:
section_output.extend(getattr(line, "comments", ()))
comments = getattr(line, "comments", ())
if comments:
if new_section_output and config.ensure_newline_before_comments:
section_output.append("")
section_output.extend(comments)
section_output.append(str(line))

section_name = section
Expand Down
17 changes: 17 additions & 0 deletions tests/test_regressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,20 @@ def test_force_single_line_shouldnt_remove_preceding_comment_lines_issue_1296():
"""
# assert isort.code(test_input) == test_input
assert isort.code(test_input, force_single_line=True) == test_input


def test_ensure_new_line_before_comments_mixed_with_ensure_newline_before_comments_1295():
"""Tests to ensure that the black profile can be used in conjunction with
force_sort_within_sections.
See: https://github.com/timothycrosley/isort/issues/1295
"""
test_input = """
from openzwave.group import ZWaveGroup
from openzwave.network import ZWaveNetwork
# pylint: disable=import-error
from openzwave.option import ZWaveOption
"""
assert isort.code(test_input, profile="black") == test_input
assert isort.code(test_input, profile="black", force_sort_within_sections=True) == test_input

0 comments on commit d4ce124

Please sign in to comment.