mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-23 21:15:19 +00:00
Avoid raising PT012 for simple with
statements (#6081)
This commit is contained in:
parent
9dfe484472
commit
62f821daaa
5 changed files with 57 additions and 81 deletions
|
@ -3,6 +3,7 @@ use rustpython_parser::ast::{Ranged, Stmt, Suite};
|
|||
use ruff_formatter::{
|
||||
format_args, write, FormatOwnedWithRule, FormatRefWithRule, FormatRuleWithOptions,
|
||||
};
|
||||
use ruff_python_ast::helpers::is_compound_statement;
|
||||
use ruff_python_trivia::lines_before;
|
||||
|
||||
use crate::context::NodeLevel;
|
||||
|
@ -142,24 +143,6 @@ const fn is_class_or_function_definition(stmt: &Stmt) -> bool {
|
|||
)
|
||||
}
|
||||
|
||||
const fn is_compound_statement(stmt: &Stmt) -> bool {
|
||||
matches!(
|
||||
stmt,
|
||||
Stmt::FunctionDef(_)
|
||||
| Stmt::AsyncFunctionDef(_)
|
||||
| Stmt::ClassDef(_)
|
||||
| Stmt::While(_)
|
||||
| Stmt::For(_)
|
||||
| Stmt::AsyncFor(_)
|
||||
| Stmt::Match(_)
|
||||
| Stmt::With(_)
|
||||
| Stmt::AsyncWith(_)
|
||||
| Stmt::If(_)
|
||||
| Stmt::Try(_)
|
||||
| Stmt::TryStar(_)
|
||||
)
|
||||
}
|
||||
|
||||
impl FormatRuleWithOptions<Suite, PyFormatContext<'_>> for FormatSuite {
|
||||
type Options = SuiteLevel;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue