Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pydoclint] Fix DOC501 panic #12428 #12435

Merged
merged 4 commits into from
Jul 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# https://github.com/astral-sh/ruff/issues/12428
def parse_bool(x, default=_parse_bool_sentinel):
"""Parse a boolean value
bool or type(default)
Raises
`ValueError`
ê>>> all(parse_bool(x) for x in [True, "yes", "Yes", "true", "True", "on", "ON", "1", 1])
"""
11 changes: 11 additions & 0 deletions crates/ruff_linter/src/rules/pydoclint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ mod tests {
use crate::test::test_path;
use crate::{assert_messages, settings};

#[test_case(Rule::DocstringMissingException, Path::new("DOC501.py"))]
fn rules(rule_code: Rule, path: &Path) -> Result<()> {
let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy());
let diagnostics = test_path(
Path::new("pydoclint").join(path).as_path(),
&settings::LinterSettings::for_rule(rule_code),
)?;
assert_messages!(snapshot, diagnostics);
Ok(())
}

#[test_case(Rule::DocstringMissingException, Path::new("DOC501_google.py"))]
#[test_case(Rule::DocstringExtraneousException, Path::new("DOC502_google.py"))]
fn rules_google_style(rule_code: Rule, path: &Path) -> Result<()> {
Expand Down
19 changes: 10 additions & 9 deletions crates/ruff_linter/src/rules/pydoclint/rules/check_docstring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ fn parse_entries(content: &str, style: SectionStyle) -> Vec<QualifiedName> {
/// ```
fn parse_entries_google(content: &str) -> Vec<QualifiedName> {
let mut entries: Vec<QualifiedName> = Vec::new();
for potential in content.split('\n') {
for potential in content.lines() {
let Some(colon_idx) = potential.find(':') else {
continue;
};
Expand All @@ -202,16 +202,17 @@ fn parse_entries_google(content: &str) -> Vec<QualifiedName> {
/// ```
fn parse_entries_numpy(content: &str) -> Vec<QualifiedName> {
let mut entries: Vec<QualifiedName> = Vec::new();
let mut split = content.split('\n');
let Some(dashes) = split.next() else {
let mut lines = content.lines();
let Some(dashes) = lines.next() else {
return entries;
};
let indentation = dashes.len() - dashes.trim_start().len();
for potential in split {
if let Some(first_char) = potential.chars().nth(indentation) {
if !first_char.is_whitespace() {
let entry = potential[indentation..].trim();
entries.push(QualifiedName::user_defined(entry));
let indentation = &dashes[..dashes.len() - dashes.trim_start().len()];
for potential in lines {
if let Some(entry) = potential.strip_prefix(indentation) {
if let Some(first_char) = entry.chars().next() {
if !first_char.is_whitespace() {
entries.push(QualifiedName::user_defined(entry.trim_end()));
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
source: crates/ruff_linter/src/rules/pydoclint/mod.rs
---

Loading