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

Conversation

ezio-melotti
Copy link
Collaborator

This draft PR adds a checker for excessive indentation, as discussed in #75.

@ezio-melotti ezio-melotti added the enhancement New feature or request label Oct 13, 2023
@ezio-melotti ezio-melotti self-assigned this Oct 13, 2023
@ezio-melotti ezio-melotti marked this pull request as draft October 13, 2023 09:43


@checker(".rst")
def check_excessive_indentation(file, lines, options=None):
Copy link
Collaborator Author

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.

sphinxlint/checkers.py Show resolved Hide resolved
Comment on lines +490 to +491
_find_list_starters = re.compile(r'^\s*(?:[-+*•‣⁃]|\d+[).]|\(\d+\)|#\.|\.\.)\s+'
r'(?!index)').match
Copy link
Collaborator Author

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.

Comment on lines +33 to +42
.. 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
Copy link
Collaborator Author

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)

Comment on lines 67 to 75
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.
? ++
Copy link
Collaborator Author

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.

Copy link
Collaborator

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).

Copy link
Collaborator Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants