-
-
Notifications
You must be signed in to change notification settings - Fork 20
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
base: main
Are you sure you want to change the base?
Add a checker for excessive indentation. #87
Conversation
|
||
|
||
@checker(".rst") | ||
def check_excessive_indentation(file, lines, options=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.