Skip to content

Commit 12c425f

Browse files
committed
Add RST220 for redefining an anonymous link
Closes #94.
1 parent da9eeb1 commit 12c425f

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

README.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ RST216 Multiple roles in interpreted text (both prefix and suffix present; only
109109
RST217 Mismatch: both interpreted text role suffix and reference suffix.
110110
RST218 Literal block expected; none found.
111111
RST219 Inline substitution_reference start-string without end-string.
112+
RST220
112113
RST299 Previously unseen warning, not yet assigned a unique code.
113114
====== =======================================================================
114115

@@ -245,7 +246,8 @@ Version History
245246
======= ========== ===========================================================
246247
Version Released Changes
247248
------- ---------- -----------------------------------------------------------
248-
v0.3.1 *Pending* - Requires Python 3.8 or later (no code changes).
249+
v0.3.1 *Pending* - Adds ``RST220`` for redefined anonymous links.
250+
- Requires Python 3.8 or later (no code changes).
249251
v0.3.0 2022-11-16 - Replaced ``setup.py`` with ``pyproject.toml``.
250252
v0.2.7 2022-07-15 - Fix where function signature occurred in docstring body.
251253
v0.2.6 2022-06-07 - Configuration option to define additional substitutions

flake8_rst_docstrings.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
"Mismatch: both interpreted text role suffix and reference suffix.": 17,
6464
"Literal block expected; none found.": 18,
6565
"Inline substitution_reference start-string without end-string.": 19,
66+
'Duplicate explicit target name: "*".': 20,
6667
}
6768

6869
# Level 3 - error
@@ -224,11 +225,12 @@ def run(self):
224225
- ast.get_docstring(node, clean=False).count("\n")
225226
- 1
226227
)
227-
assert (
228-
node.body[0].lineno >= 1 and start >= 0
229-
), "Bad start line, node line number %i for: %s\n" % (
230-
node.body[0].lineno,
231-
docstring,
228+
assert node.body[0].lineno >= 1 and start >= 0, (
229+
"Bad start line, node line number %i for: %s\n"
230+
% (
231+
node.body[0].lineno,
232+
docstring,
233+
)
232234
)
233235
for rst_error in rst_errors:
234236
# TODO - make this a configuration option?

tests/RST220/dup_explicit_target.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"""Print 'Hello world' to the terminal.
2+
3+
It is common in RST to use unnamed or anonymous links in text (like
4+
`here <https://example.com/t-and-c/>`__ and `here
5+
<https://example.org/co-op-rules.html>`__), but they should have two trailing
6+
underscores!
7+
8+
You *can* use a `single trailing underscore <https://example.com/links.html>`_
9+
but it is treated as an implicitly named link. You can use the exact same link
10+
text and URL again too (`single trailing underscore
11+
<https://example.com/links.html>`_).
12+
13+
However, the missing second underscore becomes a problem if the same link text
14+
is used again for another implicitly named link weth a different URL (e.g.
15+
missing `single trailing underscore <https://example.com/bad.html>`_ *again*).
16+
17+
What happens here?
18+
19+
$ flake8 --select RST RST220/dup_explicit_target.py
20+
RST220/dup_explicit_target.py:15:1: RST220 Duplicate explicit target name: "single trailing underscore".
21+
22+
This file triggers an error when the implicitly named link is redefined.
23+
"""
24+
25+
print("Hello world")

0 commit comments

Comments
 (0)