Skip to content

Expand directive format validation - #14184

Open
tsbinns wants to merge 5 commits into
mne-tools:mainfrom
tsbinns:fix-directives
Open

Expand directive format validation#14184
tsbinns wants to merge 5 commits into
mne-tools:mainfrom
tsbinns:fix-directives

Conversation

@tsbinns

@tsbinns tsbinns commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Fixes #14177

Comment thread doc/sphinxext/directive_formatting.py Outdated
Comment on lines +40 to +41
# Check if any directives are present
if re.search(r"\.\.\s*[a-zA-Z]+::", source_concat) is None:
# Check if text resembling directives are present
if re.search(r"\.\.\s*[a-zA-Z]+\s*:", source_concat) is None:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made the initial check for whether a document should be inspected more closely more lenient, to allow for some more malformed instances.

Comment thread doc/sphinxext/directive_formatting.py Outdated
for idx, line in enumerate(source):
# Check for missing space after '..'
missing = re.search(r"\.\.[a-zA-Z]+::", line)
missing = re.search(r"\.\.[a-zA-Z]+\s*:", line)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spaces can exist after the directive name but before the colons.

Comment thread doc/sphinxext/directive_formatting.py Outdated
Comment on lines +64 to +73
dir_pattern = r"^\s*\.\. \w+::" # line might start with whitespace
dir_pattern = r"^\s*\.\.\s*\w+:*" # line might start with whitespace

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also check a preceding blank line is present for directives without a space between .. and the directive name (that is a problem, but it's nice if we can catch multiple issues with a given directive at once) or with >1 spaces (fine).

@tsbinns

tsbinns commented Aug 20, 2026

Copy link
Copy Markdown
Contributor Author

Local testing shows these other changes not related to the bad number of colons case still catches the errors we initially looked for.

@tsbinns

tsbinns commented Aug 20, 2026

Copy link
Copy Markdown
Contributor Author

A number of cases of malformed directives which need fixing. However, the single colon form seems to have been used in some files as a way of commenting that won't be seen in the rendered docs.

@tsbinns
tsbinns marked this pull request as draft August 20, 2026 13:17
Comment on lines +113 to +116
# Strip out name
directive_name = re.sub(
r"\.\.\s*([a-zA-Z\-]+)\s*(?<!:)(:{3,}|:)(?!:)", r"\1", line
)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I neglected the fact before that single colons are acceptable for things like page links in examples/tutorials. There is now an additional check that the name of the potential bad directive matches a known sphinx directive, and only then gives a warning.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good! We shouldn't have any links named like directives and if we do we should change them :)

@tsbinns
tsbinns marked this pull request as ready for review August 20, 2026 13:51
@tsbinns

tsbinns commented Aug 20, 2026

Copy link
Copy Markdown
Contributor Author

I want to double check there isn't an instance of something that isn't being caught before merging

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expand directive format validation in doc building

2 participants