Skip to content

Add check for dangling hyphens #56

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

Merged
merged 4 commits into from
Mar 15, 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
9 changes: 9 additions & 0 deletions sphinxlint/checkers.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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