sphinx-contrib/sphinx-lint

Detecting missing newline before lists

oscargus opened this issue · 2 comments

This may be at risk of false positives, but it would be great if sphinx-lint could warn for missing newlines before lists. That is something that I personally tend to forget and have seen others miss as well.

The main problem, I guess, is to detect what a list is. A line starting with a list marker (*, -, +, 1., #., ...) may not be enough if one would like to fail it. At least two items will probably decrease the risk quite a bit.

Bullet lists can be marked by a surprisingly large number of characters:

"*", "+", "-", "•", "‣", or "⁃"

Enumerated lists take arabic, alphabetic, or roman enumerators (https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html#enumerated-lists).

For bulleted lists I'd say two or more identifiers at the same indent level, enumerated would be trickier I think, as you'd need to have a counter for the next expected character or similar.

A

This is a very common error both because other languages like MarkDown don't need the empty line and because the requirement itself is not very intuitive.

Example
.. this looks ok but is invalid
* foo
  * bar
  * bar
* foo
* foo

.. this also looks ok but is invalid
* foo
  * bar
  * bar

* foo
* foo

.. this looks weird but is valid
* foo

  * bar
  * bar
* foo
* foo

.. this looks ok and is valid
* foo

  * bar
  * bar

* foo
* foo

Checking for at least two items sounds like a good compromise. I don't think I've ever seen and (or even +) used in the wild, but they are also uncommon in general, so including them in the check shouldn't increase the risk of false positives.