mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-09 10:00:45 +00:00
Fix formatter generate.py
(#5829)
This commit is contained in:
parent
fb336898a5
commit
21063544f7
5 changed files with 393 additions and 152 deletions
9
crates/ruff_python_formatter/generate.py
Normal file → Executable file
9
crates/ruff_python_formatter/generate.py
Normal file → Executable file
|
@ -1,3 +1,5 @@
|
|||
#! /usr/bin/python
|
||||
|
||||
"""See Docs.md"""
|
||||
|
||||
# %%
|
||||
|
@ -106,11 +108,14 @@ for group, group_nodes in nodes_grouped.items():
|
|||
# Generate `FormatRule`, `AsFormat` and `IntoFormat`
|
||||
|
||||
generated = """//! This is a generated file. Don't modify it by hand! Run `crates/ruff_python_formatter/generate.py` to re-generate the file.
|
||||
#![allow(unknown_lints, clippy::default_constructed_unit_structs)]
|
||||
|
||||
use crate::context::PyFormatContext;
|
||||
use crate::{AsFormat, FormatNodeRule, IntoFormat};
|
||||
use ruff_formatter::formatter::Formatter;
|
||||
use ruff_formatter::{FormatOwnedWithRule, FormatRefWithRule, FormatResult, FormatRule};
|
||||
use rustpython_parser::ast;
|
||||
|
||||
""" # noqa: E501
|
||||
for node in nodes:
|
||||
text = f"""
|
||||
|
@ -136,7 +141,7 @@ for node in nodes:
|
|||
fn format(&self) -> Self::Format<'_> {{
|
||||
FormatRefWithRule::new(
|
||||
self,
|
||||
crate::{groups[group_for_node(node)]}::{to_camel_case(node)}::Format{node},
|
||||
crate::{groups[group_for_node(node)]}::{to_camel_case(node)}::Format{node}::default(),
|
||||
)
|
||||
}}
|
||||
}}
|
||||
|
@ -149,7 +154,7 @@ for node in nodes:
|
|||
fn into_format(self) -> Self::Format {{
|
||||
FormatOwnedWithRule::new(
|
||||
self,
|
||||
crate::{groups[group_for_node(node)]}::{to_camel_case(node)}::Format{node},
|
||||
crate::{groups[group_for_node(node)]}::{to_camel_case(node)}::Format{node}::default(),
|
||||
)
|
||||
}}
|
||||
}}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue