Skip to content

Detect docstring style mismatches by parsing, not by pattern - #321

Merged
rich-iannone merged 2 commits into
posit-dev:mainfrom
has2k1:lint-style-by-parsing
Aug 18, 2026
Merged

Detect docstring style mismatches by parsing, not by pattern#321
rich-iannone merged 2 commits into
posit-dev:mainfrom
has2k1:lint-style-by-parsing

Conversation

@has2k1

@has2k1 has2k1 commented Aug 17, 2026

Copy link
Copy Markdown
Collaborator

This PR replaces the docstring style-mismatch lint check with one that asks the parsers what they read instead of matching a hand-written list of section headers per style. The list could not track what the parsers actually do: it treated a numpy Examples section as proof of numpy style, though that section is ordinary rST found in docstrings of every style, and it stayed silent on any header absent from the list. e.t.c. Now, linting can tell you if a docstring will silently lose structure because of the parser that will be used.

has2k1 and others added 2 commits August 17, 2026 18:03
The style check matched a hand-written list of section headers per style.
The list could not track what the parsers actually read: it treated a
numpy Examples section as proof of numpy style, though that section is
ordinary rST found in docstrings of every style, and it stayed silent on
headers absent from the list.

Ask the parsers instead. For each docstring the check collects the section
kinds every style reads, and warns when a rival style reads a kind the
configured one misses, naming both. This reports a foreign section sitting
beside native ones, which the old rule suppressed, and stays silent on
docstrings genuinely written in the configured style.

Reject a configured parser outside numpy, google and sphinx with one
config error rather than a warning on every docstring.
@rich-iannone

Copy link
Copy Markdown
Member

I've made a small change. The _section_kinds() function silenced griffe's logger to suppress noise from parsing docstrings under foreign styles. However disabled = True on a parent logger doesn't stop records from child loggers reaching root handlers via propagation. We can set propagate = False to close that gap as it ensures that griffe warnings don't leak to the user during the style check.

@rich-iannone rich-iannone left a comment

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.

LGTM, thanks!

@rich-iannone
rich-iannone merged commit 6bd070e into posit-dev:main Aug 18, 2026
8 checks passed
@has2k1
has2k1 deleted the lint-style-by-parsing branch August 19, 2026 22:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants