Skip to content

Commit 4328f8f

Browse files
Add check for dangling hyphens (#56)
Co-authored-by: Jelle Zijlstra <[email protected]>
1 parent 22c47ef commit 4328f8f

File tree

6 files changed

+50
-4
lines changed

6 files changed

+50
-4
lines changed

sphinxlint/checkers.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,3 +447,12 @@ def check_block(block_lineno, block):
447447

448448
list(hide_non_rst_blocks(lines, hidden_block_cb=check_block))
449449
yield from errors
450+
451+
452+
@checker(".rst", rst_only=True)
453+
def check_dangling_hyphen(file, lines, options):
454+
"""Check for lines ending in a hyphen."""
455+
for lno, line in enumerate(lines):
456+
stripped_line = line.rstrip("\n")
457+
if re.match(r".*[a-z]-$", stripped_line):
458+
yield lno + 1, f"Line ends with dangling hyphen"

sphinxlint/rst.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
'cmdoption', 'cmember', 'confval', 'cssclass', 'ctype',
7272
'currentmodule', 'cvar', 'data', 'decorator', 'decoratormethod',
7373
'deprecated-removed', 'deprecated(?!-removed)', 'describe', 'directive',
74-
'doctest', 'envvar', 'event', 'exception', 'function', 'glossary',
74+
'envvar', 'event', 'exception', 'function', 'glossary',
7575
'highlight', 'highlightlang', 'impl-detail', 'index', 'literalinclude',
7676
'method', 'miscnews', 'module', 'moduleauthor', 'opcode', 'pdbcommand',
7777
'program', 'role', 'sectionauthor', 'seealso',
@@ -86,7 +86,7 @@
8686
'restructuredtext-test-directive', 'role', 'rubric', 'sectnum', 'table',
8787
'target-notes', 'title', 'unicode',
8888
# Sphinx and Python docs custom ones
89-
'productionlist', 'code-block',
89+
'code-block', 'doctest', 'productionlist',
9090
]
9191

9292
# fmt: on
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.. expect: Line ends with dangling hyphen (dangling-hyphen)
2+
3+
Additionally, this PEP requires that the default class definition
4+
namespace be ordered (e.g. ``OrderedDict``) by default. The long-
5+
lived class namespace (``__dict__``) will remain a ``dict``.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Additionally, this PEP requires that the default class definition
2+
namespace be ordered (e.g. ``OrderedDict``) by default. The
3+
long-lived class namespace (``__dict__``) will remain a ``dict``.
4+
5+
::
6+
7+
Traceback (most recent call last):
8+
File "<pyshell#6>", line 1, in -toplevel-
9+
d.pop()
10+
IndexError: pop from an empty deque
11+
12+
.. doctest::
13+
14+
>>> setcontext(ExtendedContext)
15+
>>> Decimal(1) / Decimal(0)
16+
Decimal('Infinity')
17+
>>> getcontext().traps[DivisionByZero] = 1
18+
>>> Decimal(1) / Decimal(0)
19+
Traceback (most recent call last):
20+
File "<pyshell#112>", line 1, in -toplevel-
21+
Decimal(1) / Decimal(0)
22+
DivisionByZero: x / 0

tests/test_filter_out_literal.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ def enumerate(sequence, start=0):
2828
Yet this line should not be dropped.
2929
3030
This one neither.
31+
32+
.. doctest::
33+
34+
>>> # This should be dropped
35+
>>> setcontext(ExtendedContext)
3136
"""
3237

3338

@@ -58,6 +63,11 @@ def enumerate(sequence, start=0):
5863
Yet this line should not be dropped.
5964
6065
This one neither.
66+
67+
.. doctest::
68+
69+
70+
6171
"""
6272

6373

tests/test_xpass_friends.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""This test needs `download-more-tests.sh`.
22
3-
This is usefull to avoid a sphinx-lint release to break many CIs.
3+
This is useful to avoid a sphinx-lint release to break many CIs.
44
"""
55

66
from pathlib import Path
@@ -16,7 +16,7 @@
1616

1717
@pytest.mark.parametrize(
1818
"file",
19-
[str(f) for f in (FIXTURE_DIR / "friends").iterdir()]
19+
[str(f) for f in (FIXTURE_DIR / "friends").iterdir() if f.name != ".DS_Store"]
2020
if (FIXTURE_DIR / "friends").is_dir()
2121
else [],
2222
)

0 commit comments

Comments
 (0)