mirror of
https://github.com/astral-sh/ruff.git
synced 2025-11-14 18:01:43 +00:00
Rename top-of-file to start-of-file (#4735)
This commit is contained in:
parent
a4f73ea8c7
commit
50053f60f3
2 changed files with 7 additions and 7 deletions
|
|
@ -66,7 +66,7 @@ impl Insertion {
|
||||||
///
|
///
|
||||||
/// The insertion returned will begin at the start of the `import os` statement, and will
|
/// The insertion returned will begin at the start of the `import os` statement, and will
|
||||||
/// include a trailing newline suffix.
|
/// include a trailing newline suffix.
|
||||||
pub(super) fn top_of_file(body: &[Stmt], locator: &Locator, stylist: &Stylist) -> Insertion {
|
pub(super) fn start_of_file(body: &[Stmt], locator: &Locator, stylist: &Stylist) -> Insertion {
|
||||||
// Skip over any docstrings.
|
// Skip over any docstrings.
|
||||||
let mut location = if let Some(location) = match_docstring_end(body) {
|
let mut location = if let Some(location) = match_docstring_end(body) {
|
||||||
// If the first token after the docstring is a semicolon, insert after the semicolon as an
|
// If the first token after the docstring is a semicolon, insert after the semicolon as an
|
||||||
|
|
@ -152,11 +152,11 @@ mod tests {
|
||||||
let tokens: Vec<LexResult> = ruff_rustpython::tokenize(contents);
|
let tokens: Vec<LexResult> = ruff_rustpython::tokenize(contents);
|
||||||
let locator = Locator::new(contents);
|
let locator = Locator::new(contents);
|
||||||
let stylist = Stylist::from_tokens(&tokens, &locator);
|
let stylist = Stylist::from_tokens(&tokens, &locator);
|
||||||
Ok(Insertion::top_of_file(&program, &locator, &stylist))
|
Ok(Insertion::start_of_file(&program, &locator, &stylist))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn top_of_file() -> Result<()> {
|
fn start_of_file() -> Result<()> {
|
||||||
let contents = "";
|
let contents = "";
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
insert(contents)?,
|
insert(contents)?,
|
||||||
|
|
|
||||||
|
|
@ -67,8 +67,8 @@ impl<'a> Importer<'a> {
|
||||||
Insertion::end_of_statement(stmt, self.locator, self.stylist)
|
Insertion::end_of_statement(stmt, self.locator, self.stylist)
|
||||||
.into_edit(&required_import)
|
.into_edit(&required_import)
|
||||||
} else {
|
} else {
|
||||||
// Insert at the top of the file.
|
// Insert at the start of the file.
|
||||||
Insertion::top_of_file(self.python_ast, self.locator, self.stylist)
|
Insertion::start_of_file(self.python_ast, self.locator, self.stylist)
|
||||||
.into_edit(&required_import)
|
.into_edit(&required_import)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -105,7 +105,7 @@ impl<'a> Importer<'a> {
|
||||||
// could be defined in the module scope, but after the function definition. In this case,
|
// could be defined in the module scope, but after the function definition. In this case,
|
||||||
// it's unclear whether we can use the symbol (the function could be called between the
|
// it's unclear whether we can use the symbol (the function could be called between the
|
||||||
// import and the current location, and thus the symbol would not be available). It's also
|
// import and the current location, and thus the symbol would not be available). It's also
|
||||||
// unclear whether should add an import statement at the top of the file, since it could
|
// unclear whether should add an import statement at the start of the file, since it could
|
||||||
// be shadowed between the import and the current location.
|
// be shadowed between the import and the current location.
|
||||||
if imported_name.range().start() > at {
|
if imported_name.range().start() > at {
|
||||||
return Some(Err(ResolutionError::ImportAfterUsage));
|
return Some(Err(ResolutionError::ImportAfterUsage));
|
||||||
|
|
@ -144,7 +144,7 @@ impl<'a> Importer<'a> {
|
||||||
/// the symbol available in the current scope along with the bound name of the symbol.
|
/// the symbol available in the current scope along with the bound name of the symbol.
|
||||||
///
|
///
|
||||||
/// For example, assuming `module` is `"functools"` and `member` is `"lru_cache"`, this function
|
/// For example, assuming `module` is `"functools"` and `member` is `"lru_cache"`, this function
|
||||||
/// could return an [`Edit`] to add `import functools` to the top of the file, alongside with
|
/// could return an [`Edit`] to add `import functools` to the start of the file, alongside with
|
||||||
/// the name on which the `lru_cache` symbol would be made available (`"functools.lru_cache"`).
|
/// the name on which the `lru_cache` symbol would be made available (`"functools.lru_cache"`).
|
||||||
fn import_symbol(
|
fn import_symbol(
|
||||||
&self,
|
&self,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue