Skip to content

Commit

Permalink
Add check for dangling hyphens (#56)
Browse files Browse the repository at this point in the history
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
  • Loading branch information
hugovk and JelleZijlstra committed Mar 15, 2023
1 parent 22c47ef commit 4328f8f
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 4 deletions.
9 changes: 9 additions & 0 deletions sphinxlint/checkers.py
Expand Up @@ -447,3 +447,12 @@ def check_block(block_lineno, block):

list(hide_non_rst_blocks(lines, hidden_block_cb=check_block))
yield from errors


@checker(".rst", rst_only=True)
def check_dangling_hyphen(file, lines, options):
"""Check for lines ending in a hyphen."""
for lno, line in enumerate(lines):
stripped_line = line.rstrip("\n")
if re.match(r".*[a-z]-$", stripped_line):
yield lno + 1, f"Line ends with dangling hyphen"
4 changes: 2 additions & 2 deletions sphinxlint/rst.py
Expand Up @@ -71,7 +71,7 @@
'cmdoption', 'cmember', 'confval', 'cssclass', 'ctype',
'currentmodule', 'cvar', 'data', 'decorator', 'decoratormethod',
'deprecated-removed', 'deprecated(?!-removed)', 'describe', 'directive',
'doctest', 'envvar', 'event', 'exception', 'function', 'glossary',
'envvar', 'event', 'exception', 'function', 'glossary',
'highlight', 'highlightlang', 'impl-detail', 'index', 'literalinclude',
'method', 'miscnews', 'module', 'moduleauthor', 'opcode', 'pdbcommand',
'program', 'role', 'sectionauthor', 'seealso',
Expand All @@ -86,7 +86,7 @@
'restructuredtext-test-directive', 'role', 'rubric', 'sectnum', 'table',
'target-notes', 'title', 'unicode',
# Sphinx and Python docs custom ones
'productionlist', 'code-block',
'code-block', 'doctest', 'productionlist',
]

# fmt: on
Expand Down
5 changes: 5 additions & 0 deletions tests/fixtures/xfail/dangling-hyphen.rst
@@ -0,0 +1,5 @@
.. expect: Line ends with dangling hyphen (dangling-hyphen)
Additionally, this PEP requires that the default class definition
namespace be ordered (e.g. ``OrderedDict``) by default. The long-
lived class namespace (``__dict__``) will remain a ``dict``.
22 changes: 22 additions & 0 deletions tests/fixtures/xpass/dangling-hyphen.rst
@@ -0,0 +1,22 @@
Additionally, this PEP requires that the default class definition
namespace be ordered (e.g. ``OrderedDict``) by default. The
long-lived class namespace (``__dict__``) will remain a ``dict``.

::

Traceback (most recent call last):
File "<pyshell#6>", line 1, in -toplevel-
d.pop()
IndexError: pop from an empty deque

.. doctest::

>>> setcontext(ExtendedContext)
>>> Decimal(1) / Decimal(0)
Decimal('Infinity')
>>> getcontext().traps[DivisionByZero] = 1
>>> Decimal(1) / Decimal(0)
Traceback (most recent call last):
File "<pyshell#112>", line 1, in -toplevel-
Decimal(1) / Decimal(0)
DivisionByZero: x / 0
10 changes: 10 additions & 0 deletions tests/test_filter_out_literal.py
Expand Up @@ -28,6 +28,11 @@ def enumerate(sequence, start=0):
Yet this line should not be dropped.
This one neither.
.. doctest::
>>> # This should be dropped
>>> setcontext(ExtendedContext)
"""


Expand Down Expand Up @@ -58,6 +63,11 @@ def enumerate(sequence, start=0):
Yet this line should not be dropped.
This one neither.
.. doctest::
"""


Expand Down
4 changes: 2 additions & 2 deletions tests/test_xpass_friends.py
@@ -1,6 +1,6 @@
"""This test needs `download-more-tests.sh`.
This is usefull to avoid a sphinx-lint release to break many CIs.
This is useful to avoid a sphinx-lint release to break many CIs.
"""

from pathlib import Path
Expand All @@ -16,7 +16,7 @@

@pytest.mark.parametrize(
"file",
[str(f) for f in (FIXTURE_DIR / "friends").iterdir()]
[str(f) for f in (FIXTURE_DIR / "friends").iterdir() if f.name != ".DS_Store"]
if (FIXTURE_DIR / "friends").is_dir()
else [],
)
Expand Down

0 comments on commit 4328f8f

Please sign in to comment.