Repository: PyCQA/docformatter (python)

Issue:
v1.6.1 - Newlines inserted around hyperlinks
Ran v1.6.1 and encountered this situation.
- config:
```
  - repo: https://github.com/PyCQA/docformatter
    rev: v1.6.1
    hooks:
      - id: docformatter
        args: [--in-place, --wrap-descriptions=88, --wrap-summaries=88]
```
- On the first pass, these hyperlinks are pushed to the next line with an additional newline above them.
- On the second pass, _another_ newline is added above them.
- On the third pass, `docformatter` doesn't make additional changes.

```
❯ cat test.py
"""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/
"""


❯ pre-commit run docformatter --files test.py 
docformatter.............................................................Failed
- hook id: docformatter
- exit code: 3

❯ cat test.py
"""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/
"""


❯ pre-commit run docformatter --files test.py 
docformatter.............................................................Failed
- hook id: docformatter
- exit code: 3

❯ cat test.py
"""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/
"""


❯ pre-commit run docformatter --files test.py 
docformatter.............................................................Passed

❯ 
```

Pull request description:
fix: adding newlines around wrapped URL
Closes #180 

Patch:
diff --git a/src/docformatter/syntax.py b/src/docformatter/syntax.py
index 6c893be..9afbeb6 100644
--- a/src/docformatter/syntax.py
+++ b/src/docformatter/syntax.py
@@ -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
 
@@ -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)}"


Test patch:
diff --git a/tests/test_format_docstring.py b/tests/test_format_docstring.py
index 92dd79c..df1d764 100644
--- a/tests/test_format_docstring.py
+++ b/tests/test_format_docstring.py
@@ -1298,6 +1298,57 @@ num_iterations is the number of updates - instead of a better definition of conv
             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):
@@ -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.
         """