Skip to content

Commit 2188172

Browse files
authored
Print multiple errors at once (#121)
1 parent b1bec13 commit 2188172

File tree

5 files changed

+15
-19
lines changed

5 files changed

+15
-19
lines changed

sphinxlint/checkers.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ def check_missing_backtick_after_role(file, lines, options=None):
5656
for paragraph_lno, paragraph in paragraphs(lines):
5757
if paragraph.count("|") > 4:
5858
return # we don't handle tables yet.
59-
error = rst.ROLE_MISSING_CLOSING_BACKTICK_RE.search(paragraph)
60-
if error:
59+
for error in rst.ROLE_MISSING_CLOSING_BACKTICK_RE.finditer(paragraph):
6160
error_offset = paragraph[: error.start()].count("\n")
6261
yield (
6362
paragraph_lno + error_offset,
@@ -126,8 +125,7 @@ def check_default_role(file, lines, options=None):
126125
for lno, line in enumerate(lines, start=1):
127126
line = clean_paragraph(line)
128127
line = escape2null(line)
129-
match = rst.INTERPRETED_TEXT_RE.search(line)
130-
if match:
128+
for match in rst.INTERPRETED_TEXT_RE.finditer(line):
131129
before_match = line[: match.start()]
132130
after_match = line[match.end() :]
133131
stripped_line = line.strip()
@@ -201,8 +199,7 @@ def check_missing_space_after_role(file, lines, options=None):
201199
"""
202200
for lno, line in enumerate(lines, start=1):
203201
line = clean_paragraph(line)
204-
role = _SUSPICIOUS_ROLE.search(line)
205-
if role:
202+
for role in _SUSPICIOUS_ROLE.finditer(line):
206203
yield lno, f"role missing (escaped) space after role: {role.group(0)!r}"
207204

208205

@@ -214,8 +211,7 @@ def check_role_without_backticks(file, lines, options=None):
214211
Good: :func:`pdb.main`
215212
"""
216213
for lno, line in enumerate(lines, start=1):
217-
no_backticks = rst.ROLE_WITH_NO_BACKTICKS_RE.search(line)
218-
if no_backticks:
214+
for no_backticks in rst.ROLE_WITH_NO_BACKTICKS_RE.finditer(line):
219215
yield lno, f"role with no backticks: {no_backticks.group(0)!r}"
220216

221217

@@ -316,8 +312,7 @@ def check_missing_space_before_role(file, lines, options=None):
316312
if paragraph.count("|") > 4:
317313
return # we don't handle tables yet.
318314
paragraph = clean_paragraph(paragraph)
319-
match = rst.ROLE_GLUED_WITH_WORD_RE.search(paragraph)
320-
if match:
315+
for match in rst.ROLE_GLUED_WITH_WORD_RE.finditer(paragraph):
321316
error_offset = paragraph[: match.start()].count("\n")
322317
if looks_like_glued(match):
323318
yield (
@@ -386,8 +381,7 @@ def check_missing_colon_in_role(file, lines, options=None):
386381
Good: :issue:`123`
387382
"""
388383
for lno, line in enumerate(lines, start=1):
389-
match = rst.ROLE_MISSING_RIGHT_COLON_RE.search(line)
390-
if match:
384+
for match in rst.ROLE_MISSING_RIGHT_COLON_RE.finditer(line):
391385
yield lno, f"role missing colon before first backtick ({match.group(0)})."
392386

393387

@@ -471,8 +465,7 @@ def check_triple_backticks(file, lines, options=None):
471465
syntax, but it's really uncommon.
472466
"""
473467
for lno, line in enumerate(lines):
474-
match = rst.TRIPLE_BACKTICKS_RE.search(line)
475-
if match:
468+
for match in rst.TRIPLE_BACKTICKS_RE.finditer(line):
476469
yield lno + 1, "There's no rst syntax using triple backticks"
477470

478471

@@ -523,5 +516,5 @@ def check_unnecessary_parentheses(filename, lines, options):
523516
Good: :func:`test`
524517
"""
525518
for lno, line in enumerate(lines, start=1):
526-
if match := rst.ROLE_WITH_UNNECESSARY_PARENTHESES_RE.search(line):
519+
for match in rst.ROLE_WITH_UNNECESSARY_PARENTHESES_RE.finditer(line):
527520
yield lno, f"Unnecessary parentheses in {match.group(0).strip()!r}"

tests/fixtures/paragraphs.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,10 @@ i.e. at :line:``70``!
7272

7373
Note that the errors report the exact
7474
line, not the first line of the paragraph
75-
so for example an error like
76-
:foo`missing colon` will be reported
77-
at line 76 and not at line 73!
75+
so for example two errors like
76+
:foo`missing colon` and :blah`other`
77+
will both be reported at line 76
78+
and not at line 73!
7879

7980

8081
.. note:

tests/fixtures/xfail/default-role-in-tables.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.. expect: default role used (hint: for inline literals, use double backticks) (default-role)
2+
.. expect: default role used (hint: for inline literals, use double backticks) (default-role)
23
34
In the following table there are a couple of default roles that should fail:
45

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.. expect: default role used (hint: for inline literals, use double backticks) (default-role)
2+
.. expect: default role used (hint: for inline literals, use double backticks) (default-role)
23
34
This is not detected: `foo`, `bar`.

tests/test_sphinxlint.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def test_line_no_in_error_msg(file, capsys):
8686
has_errors = main(["sphinxlint.py", file])
8787
out, err = capsys.readouterr()
8888
assert out == ""
89-
assert "paragraphs.rst:76: role missing colon before" in err
89+
assert err.count("paragraphs.rst:76: role missing colon before") == 2
9090
assert "paragraphs.rst:70: role use a single backtick" in err
9191
assert "paragraphs.rst:65: inline literal missing (escaped) space" in err
9292
assert has_errors

0 commit comments

Comments
 (0)