mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 21:05:08 +00:00
Fix placement of inline parameter comments (#13379)
This commit is contained in:
parent
c7b2e336f0
commit
6ac61d7b89
6 changed files with 419 additions and 63 deletions
|
@ -1,7 +1,6 @@
|
|||
use ruff_formatter::write;
|
||||
use ruff_python_ast::Parameter;
|
||||
|
||||
use crate::expression::parentheses::is_expression_parenthesized;
|
||||
use crate::prelude::*;
|
||||
use ruff_python_ast::Parameter;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatParameter;
|
||||
|
@ -16,8 +15,22 @@ impl FormatNodeRule<Parameter> for FormatParameter {
|
|||
|
||||
name.format().fmt(f)?;
|
||||
|
||||
if let Some(annotation) = annotation {
|
||||
write!(f, [token(":"), space(), annotation.format()])?;
|
||||
if let Some(annotation) = annotation.as_deref() {
|
||||
token(":").fmt(f)?;
|
||||
|
||||
if f.context().comments().has_leading(annotation)
|
||||
&& !is_expression_parenthesized(
|
||||
annotation.into(),
|
||||
f.context().comments().ranges(),
|
||||
f.context().source(),
|
||||
)
|
||||
{
|
||||
hard_line_break().fmt(f)?;
|
||||
} else {
|
||||
space().fmt(f)?;
|
||||
}
|
||||
|
||||
annotation.format().fmt(f)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue