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: add additional URL patterns #148

Merged
merged 3 commits into from
Jan 8, 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
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