-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove source_code's dependency on pydocstyle (#3366)
- Loading branch information
1 parent
709dba2
commit fc8ca6e
Showing
13 changed files
with
54 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use ruff_python_stdlib::str::{ | ||
SINGLE_QUOTE_PREFIXES, SINGLE_QUOTE_SUFFIXES, TRIPLE_QUOTE_PREFIXES, TRIPLE_QUOTE_SUFFIXES, | ||
}; | ||
|
||
/// Strip the leading and trailing quotes from a docstring. | ||
pub fn raw_contents(contents: &str) -> &str { | ||
for pattern in TRIPLE_QUOTE_PREFIXES { | ||
if contents.starts_with(pattern) { | ||
return &contents[pattern.len()..contents.len() - 3]; | ||
} | ||
} | ||
for pattern in SINGLE_QUOTE_PREFIXES { | ||
if contents.starts_with(pattern) { | ||
return &contents[pattern.len()..contents.len() - 1]; | ||
} | ||
} | ||
unreachable!("Expected docstring to start with a valid triple- or single-quote prefix") | ||
} | ||
|
||
/// Return the leading quote string for a docstring (e.g., `"""`). | ||
pub fn leading_quote(content: &str) -> Option<&str> { | ||
if let Some(first_line) = content.lines().next() { | ||
for pattern in TRIPLE_QUOTE_PREFIXES.iter().chain(SINGLE_QUOTE_PREFIXES) { | ||
if first_line.starts_with(pattern) { | ||
return Some(pattern); | ||
} | ||
} | ||
} | ||
None | ||
} | ||
|
||
/// Return the trailing quote string for a docstring (e.g., `"""`). | ||
pub fn trailing_quote(content: &str) -> Option<&&str> { | ||
TRIPLE_QUOTE_SUFFIXES | ||
.iter() | ||
.chain(SINGLE_QUOTE_SUFFIXES) | ||
.find(|&pattern| content.ends_with(pattern)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
crates/ruff/src/rules/pydocstyle/rules/multi_line_summary_start.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
crates/ruff/src/rules/pydocstyle/rules/no_surrounding_whitespace.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters