mirror of https://github.com/astral-sh/ruff
## Summary Fix panic reported in #12428. Where a string would sometimes get split within a character boundary. This bypasses the need to split the string. This does not guarantee the correct formatting of the docstring, but neither did the previous implementation. Resolves #12428 ## Test Plan Test case added to fixture
This commit is contained in:
parent
053243635c
commit
3a742c17f8
|
|
@ -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])
|
||||
"""
|
||||
|
|
@ -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<()> {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
};
|
||||
|
|
@ -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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/pydoclint/mod.rs
|
||||
---
|
||||
|
||||
Loading…
Reference in New Issue