Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: adding newlines around wrapped URL #182

Merged
merged 2 commits into from
Apr 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/docformatter/syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ def description_to_list(
if _text:
_lines.extend(_text)
_lines.append("")
with contextlib.suppress(IndexError):
if _lines[-2] == _lines[-1] == "":
_lines.pop(-1)

return _lines

Expand Down Expand Up @@ -335,6 +338,9 @@ def do_split_description(
)
)

if _lines[-1] == "":
_lines.pop(-1)

# Add the URL.
_lines.append(
f"{do_clean_url(text[_idx[0] : _idx[1]], indentation)}"
Expand Down
55 changes: 53 additions & 2 deletions tests/test_format_docstring.py
Original file line number Diff line number Diff line change
Expand Up @@ -1298,6 +1298,57 @@ def test_format_docstring_with_short_link(
INDENTATION, docstring.strip()
)

@pytest.mark.unit
@pytest.mark.parametrize(
"args",
[["--wrap-descriptions", "88", "--wrap-summaries", "88", ""]],
)
def test_format_docstring_link_only_one_newline_after_link(
self,
test_args,
args,
):
"""Links should have no newline before them and only one after.

See issue #180.
"""
uut = Formatter(
test_args,
sys.stderr,
sys.stdin,
sys.stdout,
)

docstring = '''\
"""Django settings for webapp project.

Generated by 'django-admin startproject' using Django 4.1.1.

For more information on this file, see

https://docs.djangoproject.com/en/4.1/topics/settings/

For the full list of settings and their values, see

https://docs.djangoproject.com/en/4.1/ref/settings/
"""\
'''

assert '''\
"""Django settings for webapp project.

Generated by 'django-admin startproject' using Django 4.1.1.

For more information on this file, see
https://docs.djangoproject.com/en/4.1/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.1/ref/settings/
"""\
''' == uut._do_format_docstring(
INDENTATION, docstring.strip()
)

@pytest.mark.unit
@pytest.mark.parametrize("args", [[""]])
def test_format_docstring_with_class_attributes(self, test_args, args):
Expand Down Expand Up @@ -1329,10 +1380,10 @@ class TestClass:

@pytest.mark.unit
@pytest.mark.parametrize("args", [[""]])
def test_format_docstring_no_blank_in_summary_with_symbol(
def test_format_docstring_no_newline_in_summary_with_symbol(
self, test_args, args
):
"""Wrap long class attribute docstrings.
"""Wrap summary with symbol should not add newline.

See issue #79.
"""
Expand Down