mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-17 09:00:26 +00:00
[ruff
] Trigger RUF037
for empty string and byte strings (#18862)
Some checks are pending
CI / cargo fmt (push) Waiting to run
CI / Determine changes (push) Waiting to run
CI / cargo clippy (push) Blocked by required conditions
CI / cargo test (linux) (push) Blocked by required conditions
CI / cargo test (linux, release) (push) Blocked by required conditions
CI / cargo test (windows) (push) Blocked by required conditions
CI / cargo test (wasm) (push) Blocked by required conditions
CI / cargo build (release) (push) Waiting to run
CI / cargo build (msrv) (push) Blocked by required conditions
CI / cargo fuzz build (push) Blocked by required conditions
CI / fuzz parser (push) Blocked by required conditions
CI / test scripts (push) Blocked by required conditions
CI / ecosystem (push) Blocked by required conditions
CI / Fuzz for new ty panics (push) Blocked by required conditions
CI / cargo shear (push) Blocked by required conditions
CI / python package (push) Waiting to run
CI / pre-commit (push) Waiting to run
CI / mkdocs (push) Waiting to run
CI / formatter instabilities and black similarity (push) Blocked by required conditions
CI / test ruff-lsp (push) Blocked by required conditions
CI / check playground (push) Blocked by required conditions
CI / benchmarks-instrumented (push) Blocked by required conditions
CI / benchmarks-walltime (push) Blocked by required conditions
[ty Playground] Release / publish (push) Waiting to run
Some checks are pending
CI / cargo fmt (push) Waiting to run
CI / Determine changes (push) Waiting to run
CI / cargo clippy (push) Blocked by required conditions
CI / cargo test (linux) (push) Blocked by required conditions
CI / cargo test (linux, release) (push) Blocked by required conditions
CI / cargo test (windows) (push) Blocked by required conditions
CI / cargo test (wasm) (push) Blocked by required conditions
CI / cargo build (release) (push) Waiting to run
CI / cargo build (msrv) (push) Blocked by required conditions
CI / cargo fuzz build (push) Blocked by required conditions
CI / fuzz parser (push) Blocked by required conditions
CI / test scripts (push) Blocked by required conditions
CI / ecosystem (push) Blocked by required conditions
CI / Fuzz for new ty panics (push) Blocked by required conditions
CI / cargo shear (push) Blocked by required conditions
CI / python package (push) Waiting to run
CI / pre-commit (push) Waiting to run
CI / mkdocs (push) Waiting to run
CI / formatter instabilities and black similarity (push) Blocked by required conditions
CI / test ruff-lsp (push) Blocked by required conditions
CI / check playground (push) Blocked by required conditions
CI / benchmarks-instrumented (push) Blocked by required conditions
CI / benchmarks-walltime (push) Blocked by required conditions
[ty Playground] Release / publish (push) Waiting to run
This commit is contained in:
parent
e474f36473
commit
ca7933804e
4 changed files with 145 additions and 1 deletions
|
@ -504,6 +504,20 @@ impl FStringValue {
|
|||
pub fn elements(&self) -> impl Iterator<Item = &InterpolatedStringElement> {
|
||||
self.f_strings().flat_map(|fstring| fstring.elements.iter())
|
||||
}
|
||||
|
||||
/// Returns `true` if the node represents an empty f-string literal.
|
||||
///
|
||||
/// Noteh that a [`FStringValue`] node will always have >= 1 [`FStringPart`]s inside it.
|
||||
/// This method checks whether the value of the concatenated parts is equal to the empty
|
||||
/// f-string, not whether the f-string has 0 parts inside it.
|
||||
pub fn is_empty_literal(&self) -> bool {
|
||||
match &self.inner {
|
||||
FStringValueInner::Single(fstring_part) => fstring_part.is_empty_literal(),
|
||||
FStringValueInner::Concatenated(fstring_parts) => {
|
||||
fstring_parts.iter().all(FStringPart::is_empty_literal)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> IntoIterator for &'a FStringValue {
|
||||
|
@ -550,6 +564,13 @@ impl FStringPart {
|
|||
Self::FString(f_string) => f_string.flags.quote_style(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_empty_literal(&self) -> bool {
|
||||
match &self {
|
||||
FStringPart::Literal(string_literal) => string_literal.value.is_empty(),
|
||||
FStringPart::FString(f_string) => f_string.elements.is_empty(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Ranged for FStringPart {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue