Skip to content
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

Add a checker for excessive indentation. #87

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
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
Prev Previous commit
Skip literal blocks.
ezio-melotti committed Oct 13, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 7345443c808e96db19b8bf21d1bc38c3e67eacfa
3 changes: 2 additions & 1 deletion sphinxlint/checkers.py
Original file line number Diff line number Diff line change
@@ -503,7 +503,8 @@ def check_excessive_indentation(file, lines, options=None):
"""
errors = []
last_ind_level = 0
for lineno, line in enumerate(lines, start=1):
for lineno, line in enumerate(hide_non_rst_blocks(lines), start=1):
# print(line, end='')
if not line.strip():
continue
curr_ind_level = len(_find_leading_spaces(line).group())
13 changes: 1 addition & 12 deletions tests/fixtures/xfail/excessive-indentation.rst
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@
.. expect: 51: Excessive indentation in nested section (excessive-indentation)
.. expect: 53: Excessive indentation in nested section (excessive-indentation)
.. expect: 57: Excessive indentation in nested section (excessive-indentation)
.. expect: 71: Excessive indentation in nested section (excessive-indentation)


The most common mistakes is indenting lists and directives under a paragraph:

@@ -62,14 +62,3 @@ Each of these should give an error, since they are all indented wrong.
Numbered lists that start with letters (a. b. c. ...)
and roman numerals (I. II. III. ...) are only supported by Sphinx 7+
so we just ignore them


This is a known false positive:

>>> import sys
>>> sys.stdout.writelines(result)
1. Beautiful is better than ugly.
- 2. Explicit is better than implicit.
- 3. Simple is better than complex.
+ 3. Simple is better than complex.
? ++