Skip to content

Commit

Permalink
Fixed #1315: Extra newline before comment with -n + --fss.
Browse files Browse the repository at this point in the history
  • Loading branch information
timothycrosley committed Jul 14, 2020
1 parent ef2d393 commit 94c3d6b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Expand Up @@ -3,12 +3,13 @@ Changelog

NOTE: isort follows the [semver](https://semver.org/) versioning standard.

### 5.1.0 July 12, 2020
### 5.1.0 July TBD, 2020
- isort now throws an exception if an invalid settings path is given (issue #1174).
- Fixed #1178: support for semicolons in decorators.
- Fixed #1315: Extra newline before comment with -n + --fss.

### 5.0.9 July 11, 2020
- Fixed #1301: Import headings in nested sections leads to check errors
is

### 5.0.8 July 11, 2020
- Fixed #1277 & #1278: New line detection issues on Windows.
Expand Down
2 changes: 1 addition & 1 deletion isort/output.py
Expand Up @@ -132,7 +132,7 @@ def sorted_imports(
for line in new_section_output:
comments = getattr(line, "comments", ())
if comments:
if new_section_output and config.ensure_newline_before_comments:
if section_output and config.ensure_newline_before_comments:
section_output.append("")
section_output.extend(comments)
section_output.append(str(line))
Expand Down
34 changes: 34 additions & 0 deletions tests/test_regressions.py
Expand Up @@ -289,3 +289,37 @@ def test_isort_shouldnt_fail_on_long_from_with_dot_issue_1190():
)
"""
)


def test_isort_shouldnt_add_extra_new_line_when_fass_and_n_issue_1315():
"""Test to ensure isort doesnt add a second extra new line when combining --fss and -n options.
See: https://github.com/timothycrosley/isort/issues/1315
"""
assert isort.check_code(
"""import sys
# Comment canary
from . import foo
""",
ensure_newline_before_comments=True, # -n
force_sort_within_sections=True, # -fss
show_diff=True, # for better debugging in the case the test case fails.
)

assert (
isort.code(
"""
from . import foo
# Comment canary
from .. import foo
""",
ensure_newline_before_comments=True,
force_sort_within_sections=True,
)
== """
from . import foo
# Comment canary
from .. import foo
"""
)

0 comments on commit 94c3d6b

Please sign in to comment.