mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-23 21:15:19 +00:00
Rename end_of_statement
to end_of_last_statement
(#3775)
This commit is contained in:
parent
990b378c4d
commit
22d5b0071d
3 changed files with 39 additions and 32 deletions
|
@ -13,7 +13,6 @@ use rustpython_parser::{lexer, Mode, StringKind, Tok};
|
|||
use smallvec::{smallvec, SmallVec};
|
||||
|
||||
use crate::context::Context;
|
||||
use crate::newlines::StrExt;
|
||||
use crate::scope::{Binding, BindingKind};
|
||||
use crate::source_code::{Generator, Indexer, Locator, Stylist};
|
||||
use crate::types::{CallPath, Range};
|
||||
|
@ -1139,32 +1138,6 @@ pub fn first_colon_range(range: Range, locator: &Locator) -> Option<Range> {
|
|||
range
|
||||
}
|
||||
|
||||
/// Given a statement, find its "logical end".
|
||||
///
|
||||
/// For example: the statement could be following by a trailing semicolon, by an end-of-line
|
||||
/// comment, or by any number of continuation lines (and then by a comment, and so on).
|
||||
pub fn end_of_statement(stmt: &Stmt, locator: &Locator) -> Location {
|
||||
let contents = locator.skip(stmt.end_location.unwrap());
|
||||
|
||||
// End-of-file, so just return the end of the statement.
|
||||
if contents.is_empty() {
|
||||
return stmt.end_location.unwrap();
|
||||
}
|
||||
|
||||
// Otherwise, find the end of the last line that's "part of" the statement.
|
||||
for (lineno, line) in contents.universal_newlines().enumerate() {
|
||||
if line.ends_with('\\') {
|
||||
continue;
|
||||
}
|
||||
return to_absolute(
|
||||
Location::new(lineno + 1, line.chars().count()),
|
||||
stmt.end_location.unwrap(),
|
||||
);
|
||||
}
|
||||
|
||||
unreachable!("Expected to find end-of-statement")
|
||||
}
|
||||
|
||||
/// Return the `Range` of the first `Elif` or `Else` token in an `If` statement.
|
||||
pub fn elif_else_range(stmt: &Stmt, locator: &Locator) -> Option<Range> {
|
||||
let StmtKind::If { body, orelse, .. } = &stmt.node else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue