mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-27 20:42:10 +00:00
Move Python whitespace utilities into new ruff_python_whitespace
crate (#4993)
## Summary `ruff_newlines` becomes `ruff_python_whitespace`, and includes the existing "universal newline" handlers alongside the Python whitespace-specific utilities.
This commit is contained in:
parent
e86f12a1ec
commit
1d756dc3a7
57 changed files with 153 additions and 140 deletions
15
crates/ruff_python_whitespace/src/whitespace.rs
Normal file
15
crates/ruff_python_whitespace/src/whitespace.rs
Normal file
|
@ -0,0 +1,15 @@
|
|||
/// Returns `true` for [whitespace](https://docs.python.org/3/reference/lexical_analysis.html#whitespace-between-tokens)
|
||||
/// characters.
|
||||
pub const fn is_python_whitespace(c: char) -> bool {
|
||||
matches!(
|
||||
c,
|
||||
// Space, tab, or form-feed
|
||||
' ' | '\t' | '\x0C'
|
||||
)
|
||||
}
|
||||
|
||||
/// Extract the leading indentation from a line.
|
||||
pub fn leading_indentation(line: &str) -> &str {
|
||||
line.find(|char: char| !is_python_whitespace(char))
|
||||
.map_or(line, |index| &line[..index])
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue