Add a checker for excessive indentation.#87
Add a checker for excessive indentation.#87ezio-melotti wants to merge 2 commits intosphinx-contrib:mainfrom
Conversation
|
|
||
|
|
||
| @checker(".rst") | ||
| def check_excessive_indentation(file, lines, options=None): |
There was a problem hiding this comment.
The previous checker is called bad_dedent, so this could be called bad_indent. However indent sounds more generic since it might refer to both indentation and dedentation, whereas this checker only deals with excessive indentation.
| _find_list_starters = re.compile(r'^\s*(?:[-+*•‣⁃]|\d+[).]|\(\d+\)|#\.|\.\.)\s+' | ||
| r'(?!index)').match |
There was a problem hiding this comment.
This currently combines unnumbered and numbered lists with directives, however we might have to handle them differently, since there are more restrictions for things nested under lists than under directives.
| .. note:: | ||
|
|
||
| * the opposite is also true | ||
| * lists nested under directives | ||
| * should be indented properly | ||
| * (but maybe they don't have to?) | ||
|
|
||
| .. note:: | ||
|
|
||
| .. note:: this is also not allowed atm, but maybe it should |
There was a problem hiding this comment.
These are currently detected as errors, but technically they could be ok and they should be allowed. (see previous comment too)
| 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. | ||
| ? ++ |
There was a problem hiding this comment.
I found this in library/difflib.rst in the CPython docs, and it fails on line 71, on the indented 1.. This shouldn't happen, so the checker should be fixed to ignore the content of code blocks.
There was a problem hiding this comment.
Is this really a code block without the double colon? According to the spec it should be a block quote, but according to the html outout it looks like a code-block. Strange.
If detected as a code block by sphinx-lint it is hidden from your test (see git grep rst_only).
There was a problem hiding this comment.
Indeed the problem was the missing double colon. After adding that and using hide_non_rst_blocks sphinx-lint skipped the block and avoided the false-positive.
This draft PR adds a checker for excessive indentation, as discussed in #75.