Rename top-of-file to start-of-file (#4735)

This commit is contained in:
Charlie Marsh 2023-05-30 17:53:36 -04:00 committed by GitHub
parent a4f73ea8c7
commit 50053f60f3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 7 deletions

View file

@ -66,7 +66,7 @@ impl Insertion {
///
/// The insertion returned will begin at the start of the `import os` statement, and will
/// 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.
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
@ -152,11 +152,11 @@ mod tests {
let tokens: Vec<LexResult> = ruff_rustpython::tokenize(contents);
let locator = Locator::new(contents);
let stylist = Stylist::from_tokens(&tokens, &locator);
Ok(Insertion::top_of_file(&program, &locator, &stylist))
Ok(Insertion::start_of_file(&program, &locator, &stylist))
}
#[test]
fn top_of_file() -> Result<()> {
fn start_of_file() -> Result<()> {
let contents = "";
assert_eq!(
insert(contents)?,

View file

@ -67,8 +67,8 @@ impl<'a> Importer<'a> {
Insertion::end_of_statement(stmt, self.locator, self.stylist)
.into_edit(&required_import)
} else {
// Insert at the top of the file.
Insertion::top_of_file(self.python_ast, self.locator, self.stylist)
// Insert at the start of the file.
Insertion::start_of_file(self.python_ast, self.locator, self.stylist)
.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,
// 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
// 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.
if imported_name.range().start() > at {
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.
///
/// 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"`).
fn import_symbol(
&self,