mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 21:05:08 +00:00
Format Identifier (#5255)
This commit is contained in:
parent
6155fd647d
commit
e47aa468d5
4 changed files with 33 additions and 13 deletions
28
crates/ruff_python_formatter/src/other/identifier.rs
Normal file
28
crates/ruff_python_formatter/src/other/identifier.rs
Normal file
|
@ -0,0 +1,28 @@
|
|||
use crate::prelude::*;
|
||||
use crate::AsFormat;
|
||||
use ruff_formatter::{FormatOwnedWithRule, FormatRefWithRule};
|
||||
use rustpython_parser::ast::{Identifier, Ranged};
|
||||
|
||||
pub struct FormatIdentifier;
|
||||
|
||||
impl FormatRule<Identifier, PyFormatContext<'_>> for FormatIdentifier {
|
||||
fn fmt(&self, item: &Identifier, f: &mut PyFormatter) -> FormatResult<()> {
|
||||
source_text_slice(item.range(), ContainsNewlines::No).fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast> AsFormat<PyFormatContext<'ast>> for Identifier {
|
||||
type Format<'a> = FormatRefWithRule<'a, Identifier, FormatIdentifier, PyFormatContext<'ast>>;
|
||||
|
||||
fn format(&self) -> Self::Format<'_> {
|
||||
FormatRefWithRule::new(self, FormatIdentifier)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast> IntoFormat<PyFormatContext<'ast>> for Identifier {
|
||||
type Format = FormatOwnedWithRule<Identifier, FormatIdentifier, PyFormatContext<'ast>>;
|
||||
|
||||
fn into_format(self) -> Self::Format {
|
||||
FormatOwnedWithRule::new(self, FormatIdentifier)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue