Skip to content

Commit

Permalink
fix: add additional URL patterns (#148)
Browse files Browse the repository at this point in the history
* fix: add additional URL patterns

* test: add test class and tests for URL patterns

* style: fix rstcheck error
  • Loading branch information
weibullguy committed Jan 8, 2023
1 parent 518018f commit 3c9c239
Show file tree
Hide file tree
Showing 3 changed files with 508 additions and 23 deletions.
24 changes: 13 additions & 11 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ docformatter
:target: https://pycqa.github.io/isort/
.. |SELF| image:: https://img.shields.io/badge/%20formatter-docformatter-fedcba.svg
:target: https://github.com/PyCQA/docformatter
.. |DOCSTYLE| image:: https://img.shields.io/badge/%20style-numpy-459db9.svg
.. |SPHINXSTYLE| image:: https://img.shields.io/badge/%20style-sphinx-0a507a.svg
:target: https://www.sphinx-doc.org/en/master/usage/index.html
.. |NUMPSTYLE| image:: https://img.shields.io/badge/%20style-numpy-459db9.svg
:target: https://numpydoc.readthedocs.io/en/latest/format.html
.. |GOOGSTYLE| image:: https://img.shields.io/badge/%20style-google-3666d6.svg
:target: https://google.github.io/styleguide/pyguide.html#s3.8-comments-and-docstrings

.. |VERSION| image:: https://img.shields.io/pypi/v/docformatter
.. |LICENSE| image:: https://img.shields.io/pypi/l/docformatter
Expand All @@ -27,7 +31,7 @@ docformatter
+----------------+----------------------------------------------------------+
| **Code** + |BLACK| |ISORT| +
+----------------+----------------------------------------------------------+
| **Docstrings** + |SELF| |DOCSTYLE| +
| **Docstrings** + |SELF| |NUMPSTYLE| +
+----------------+----------------------------------------------------------+
| **GitHub** + |CI| |CONTRIBUTORS| |COMMIT| +
+----------------+----------------------------------------------------------+
Expand Down Expand Up @@ -171,28 +175,26 @@ Do you use *docformatter*? What style docstrings do you use? Add some badges t
.. image:: https://img.shields.io/badge/%20formatter-docformatter-fedcba.svg
:target: https://github.com/PyCQA/docformatter
.. image:: https://img.shields.io/badge/%20style-google-3666d6.svg
:target: https://google.github.io/styleguide/pyguide.html#s3.8-comments-and-docstrings
|SPHINXSTYLE|

.. code-block::
.. image:: https://img.shields.io/badge/%20style-google-3666d6.svg
:target: https://google.github.io/styleguide/pyguide.html#s3.8-comments-and-docstrings
.. image:: https://img.shields.io/badge/%20style-sphinx-0a507a.svg
:target: https://www.sphinx-doc.org/en/master/usage/index.html
|DOCSTYLE|
|NUMPSTYLE|

.. code-block::
.. image:: https://img.shields.io/badge/%20style-numpy-459db9.svg
:target: https://numpydoc.readthedocs.io/en/latest/format.html
.. image:: https://img.shields.io/badge/%20style-sphinx-0a507a.svg
:target: https://www.sphinx-doc.org/en/master/usage/index.html
|GOOGSTYLE|

.. code-block::
.. image:: https://img.shields.io/badge/%20style-sphinx-0a507a.svg
:target: https://www.sphinx-doc.org/en/master/usage/index.html
.. image:: https://img.shields.io/badge/%20style-google-3666d6.svg
:target: https://google.github.io/styleguide/pyguide.html#s3.8-comments-and-docstrings
Issues
======
Expand Down
80 changes: 72 additions & 8 deletions src/docformatter/syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,7 @@ def do_preserve_links(
if len(lines) < 2:
return lines

url = next(
(
line
for line in lines
if re.search(r"<?(http://|https://|ftp://|sftp://)", line)
),
"",
)
url = is_some_sort_of_link(lines)

if url != "":
url_idx = lines.index(url)
Expand Down Expand Up @@ -165,6 +158,77 @@ def do_preserve_links(
return lines


def is_some_sort_of_link(lines: List[str]) -> str:
"""Determine if docstring line contains a link.
URL patterns based on table at
<https://en.wikipedia.org/wiki/List_of_URI_schemes>
Parameters
----------
lines: str
the list of docstring lines to check for a link pattern.
Returns
-------
url: str
the line with the url pattern.
"""
url_patterns = (
"("
"afp://|"
"apt:|"
"bitcoin:|"
"chrome://|"
"cvs://|"
"dav://|"
"dns:|"
"file://|"
"finger://|"
"fish://|"
"ftp://|"
"ftps://|"
"git://|"
"http://|"
"https://|"
"imap://|"
"ipp://|"
"ipps://|"
"irc://|"
"irc6://|"
"ircs://|"
"jar:|"
"ldap://|"
"ldaps://|"
"mailto:|"
"news:|"
"nfs://|"
"nntp://|"
"pop://|"
"rsync://|"
"s3://|"
"sftp://|"
"shttp://|"
"sip:|"
"sips:|"
"smb://|"
"sms:|"
"snmp://|"
"ssh://|"
"svn://|"
"telnet://|"
"vnc://|"
"xmpp:|"
"xri://"
")"
)

return next(
(line for line in lines if re.search(rf"<?{url_patterns}", line)),
"",
)


# pylint: disable=line-too-long
def is_some_sort_of_list(text, strict) -> bool:
"""Determine if docstring is a reST list.
Expand Down
Loading

0 comments on commit 3c9c239

Please sign in to comment.