[pydoclint] Implement docstring-missing-exception and docstring-extraneous-exception (DOC501, DOC502)#11471
Conversation
CodSpeed Performance ReportMerging #11471 will degrade performances by 97.48%Comparing Summary
Benchmarks breakdown
|
|
| code | total | + violation | - violation | + fix | - fix |
|---|---|---|---|---|---|
| DAR401 | 2237 | 2237 | 0 | 0 | 0 |
| DAR402 | 2 | 2 | 0 | 0 | 0 |
Formatter (stable)
✅ ecosystem check detected no format changes.
Formatter (preview)
✅ ecosystem check detected no format changes.
|
If this PR is accepted, will this preclude |
|
I'm not opposed to using pydocstyle instead, but I'll wait until I get a review from the ruff team to change anything. |
charliermarsh
left a comment
There was a problem hiding this comment.
Nice, this looks great. I'll make a few tweaks and merge today.
|
@charliermarsh where do you stand on darglint vs pydoclint as mentioned above |
|
Honestly, finding it hard to have a strong opinion on it... What do you think? Absent other opinions, let's run with |
|
Sounds reasonable to me |
darglint] Implement docstring-missing-exception and docstring-extraneous-exception (DAR401, DAR402)pydoclint] Implement docstring-missing-exception and docstring-extraneous-exception (DOC501, DOC502)
crates/ruff_linter/src/rules/pydoclint/rules/check_docstring.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/pydoclint/rules/check_docstring.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/pydoclint/rules/check_docstring.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/pydoclint/rules/check_docstring.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/pydoclint/rules/check_docstring.rs
Outdated
Show resolved
Hide resolved
| impl<'a> DocstringEntries<'a> { | ||
| /// Return the raised exceptions for the docstring, or `None` if the docstring does not contain | ||
| /// a `Raises` section. | ||
| fn from_sections(sections: &'a SectionContexts, style: SectionStyle) -> Option<Self> { |
There was a problem hiding this comment.
I changed this to return None when there's no section, so we didn't have to unwrap the raised_exceptions_range. Feel free to revert in future PRs if that gets in the way, though I think something like that is useful to get rid of the unwrap.
|
Do we need to update title and description of #458 to keep tracking future implementations for this plugin? |
|
I'm thinking to open a new issue to track |
Summary
These are the first rules implemented as part of #458, but I plan to implement more.
Specifically, this implements
docstring-missing-exceptionwhich checks for raised exceptions not documented in the docstring, anddocstring-extraneous-exceptionwhich checks for exceptions in the docstring not present in the body.Test Plan
Test fixtures added for both google and numpy style.