sphinx-lint icon indicating copy to clipboard operation
sphinx-lint copied to clipboard

Ignore markup errors in comments

Open ezio-melotti opened this issue 3 years ago • 5 comments

I ran sphinx-lint against a project that includes the following in the index.rst:

.. <project name> documentation master file, created by
   sphinx-quickstart on Sat Aug 28 22:34:16 2021.
   You can adapt this file completely to your liking, but it should at least
   contain the root `toctree` directive.

Since I was using the --enable default-role option, I got the following error, even though the markup appears in a comment:

index.rst:4: default role used (hint: for inline literals, use double backticks) (default-role)

Should sphinx-lint ignore markup errors in a comment?

ezio-melotti avatar Jun 10 '22 02:06 ezio-melotti

Perhaps a flag to ignore comments? Sometimes when writing documentation I comment things out that I want to return to later. However that is a niche use-case---Ezio's example is probably more common where people don't care about the markup in comments.

A

AA-Turner avatar Jun 10 '22 19:06 AA-Turner

I would ignore markup in comments, just as (I assume) Sphinx also does.

Similar to https://github.com/sphinx-contrib/sphinx-lint/issues/34, where we want to ignore markup inside code blocks.

hugovk avatar Jun 10 '22 19:06 hugovk

As far as I know sphinx-lint works line by line, without parsing the markup (it only uses regexes), so this might be tricky to implement unless we change it to handle more context.

ezio-melotti avatar Jun 10 '22 19:06 ezio-melotti

Docutils (and hence also Sphinx) just includes the text verbatim in a comment node:

(docutils) S:\Development\docutils>type comment-test.rst
.. This is a reStructuredText comment with :pep`42`` misformed markup.

(docutils) S:\Development\docutils>docutils --writer pseudoxml comment-test.rst
<document source="comment-test.rst">
    <comment xml:space="preserve">
        This is a reStructuredText comment with :pep`42`` misformed markup.

A

AA-Turner avatar Jun 10 '22 19:06 AA-Turner

There is a check for comments, but only on the same line -- the in_literal state logic could be expanded to comments?

https://github.com/sphinx-contrib/sphinx-lint/blob/b3775563717e4c875cabd0e6709c47094a8d0bfa/sphinxlint.py#L511-L512

A

AA-Turner avatar Jun 10 '22 19:06 AA-Turner