mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 12:55:05 +00:00
Split implicit concatenated strings before binary expressions (#7145)
This commit is contained in:
parent
9671922e40
commit
e376c3ff7e
20 changed files with 1067 additions and 366 deletions
44
crates/ruff_python_formatter/src/expression/operator.rs
Normal file
44
crates/ruff_python_formatter/src/expression/operator.rs
Normal file
|
@ -0,0 +1,44 @@
|
|||
use crate::prelude::*;
|
||||
use ruff_formatter::{FormatOwnedWithRule, FormatRefWithRule};
|
||||
use ruff_python_ast::Operator;
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct FormatOperator;
|
||||
|
||||
impl<'ast> AsFormat<PyFormatContext<'ast>> for Operator {
|
||||
type Format<'a> = FormatRefWithRule<'a, Operator, FormatOperator, PyFormatContext<'ast>>;
|
||||
|
||||
fn format(&self) -> Self::Format<'_> {
|
||||
FormatRefWithRule::new(self, FormatOperator)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast> IntoFormat<PyFormatContext<'ast>> for Operator {
|
||||
type Format = FormatOwnedWithRule<Operator, FormatOperator, PyFormatContext<'ast>>;
|
||||
|
||||
fn into_format(self) -> Self::Format {
|
||||
FormatOwnedWithRule::new(self, FormatOperator)
|
||||
}
|
||||
}
|
||||
|
||||
impl FormatRule<Operator, PyFormatContext<'_>> for FormatOperator {
|
||||
fn fmt(&self, item: &Operator, f: &mut PyFormatter) -> FormatResult<()> {
|
||||
let operator = match item {
|
||||
Operator::Add => "+",
|
||||
Operator::Sub => "-",
|
||||
Operator::Mult => "*",
|
||||
Operator::MatMult => "@",
|
||||
Operator::Div => "/",
|
||||
Operator::Mod => "%",
|
||||
Operator::Pow => "**",
|
||||
Operator::LShift => "<<",
|
||||
Operator::RShift => ">>",
|
||||
Operator::BitOr => "|",
|
||||
Operator::BitXor => "^",
|
||||
Operator::BitAnd => "&",
|
||||
Operator::FloorDiv => "//",
|
||||
};
|
||||
|
||||
token(operator).fmt(f)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue