Skip to content

Commit

Permalink
fix: remove blank after comment (#177)
Browse files Browse the repository at this point in the history
* fix: removing blank line after comment

* test: add test for removing blank line after comment
  • Loading branch information
weibullguy committed Apr 22, 2023
1 parent 570825a commit 91e3c9d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/docformatter/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import collections
import contextlib
import io
import re
import tokenize
from typing import TextIO, Tuple

Expand Down Expand Up @@ -587,11 +588,15 @@ def _do_remove_blank_lines_after_docstring(modified_tokens):
].strip().startswith(
'"""'
)
_comment_follows = re.search(
r"\"\"\" *#", modified_tokens[_idx - 4][4]
)

if (
_token[0] == 1
and not _is_definition
and not _is_docstring
and not _comment_follows
and _after_definition
and _after_docstring
):
Expand Down
43 changes: 43 additions & 0 deletions tests/test_format_docstring.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,49 @@ class AcceptLanguageHeader(ExtendedSchemaNode): \
# FIXME: oneOf validator for supported languages (?)'
assert docstring == uut._do_format_code(docstring)

@pytest.mark.unit
@pytest.mark.parametrize("args", [[""]])
def test_format_docstring_leave_blank_line_after_comment(self,
test_args,
args,):
"""Leave blank lines after docstring followed by a comment.
See issue #176.
"""
uut = Formatter(
test_args,
sys.stderr,
sys.stdin,
sys.stdout,
)

docstring = '''\
def Class1:
"""Class.""" #noqa
attribute
"""Attr."""
def Class2:
"""Class."""
attribute
"""Attr."""
def Class3:
"""Class docstring.
With long description.
""" #noqa
attribute
"""Attr."""
'''
assert docstring == uut._do_format_code(docstring)


class TestFormatLists:
"""Class for testing format_docstring() with lists in the docstring."""

Expand Down

0 comments on commit 91e3c9d

Please sign in to comment.