mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 21:05:08 +00:00
Format import statements (#5493)
## Summary Format import statements in all their variants. Specifically, this implemented formatting `StmtImport`, `StmtImportFrom` and `Alias`. ## Test Plan I added some custom snapshots, even though this has been covered well by black's tests.
This commit is contained in:
parent
6acc316d19
commit
787e2fd49d
26 changed files with 304 additions and 991 deletions
|
@ -1,5 +1,6 @@
|
|||
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::{write, Buffer, FormatResult};
|
||||
use crate::{AsFormat, FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::prelude::{space, text};
|
||||
use ruff_formatter::{write, Buffer, Format, FormatResult};
|
||||
use rustpython_parser::ast::Alias;
|
||||
|
||||
#[derive(Default)]
|
||||
|
@ -7,6 +8,15 @@ pub struct FormatAlias;
|
|||
|
||||
impl FormatNodeRule<Alias> for FormatAlias {
|
||||
fn fmt_fields(&self, item: &Alias, f: &mut PyFormatter) -> FormatResult<()> {
|
||||
write!(f, [not_yet_implemented(item)])
|
||||
let Alias {
|
||||
range: _,
|
||||
name,
|
||||
asname,
|
||||
} = item;
|
||||
name.format().fmt(f)?;
|
||||
if let Some(asname) = asname {
|
||||
write!(f, [space(), text("as"), space(), asname.format()])?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue