mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-07 21:25:08 +00:00
Generate FormatRule definitions (#4724)
* Generate FormatRule definitions * Generate verbatim output * pub(crate) everything * clippy fix * Update crates/ruff_python_formatter/src/lib.rs Co-authored-by: Micha Reiser <micha@reiser.io> * Update crates/ruff_python_formatter/src/lib.rs Co-authored-by: Micha Reiser <micha@reiser.io> * stub out with Ok(()) again * Update crates/ruff_python_formatter/src/lib.rs Co-authored-by: Micha Reiser <micha@reiser.io> * PyFormatContext::{contents, locator} with `#[allow(unused)]` * Can't leak private type * remove commented code * Fix ruff errors * pub struct Format{node} due to rust rules --------- Co-authored-by: Julian LaNeve <lanevejulian@gmail.com> Co-authored-by: Micha Reiser <micha@reiser.io>
This commit is contained in:
parent
b7294b48e7
commit
0945803427
88 changed files with 4136 additions and 46 deletions
|
@ -39,6 +39,7 @@ use crate::formatter::Formatter;
|
|||
use crate::group_id::UniqueGroupIdBuilder;
|
||||
use crate::prelude::TagKind;
|
||||
use std::fmt::Debug;
|
||||
use std::marker::PhantomData;
|
||||
|
||||
use crate::format_element::document::Document;
|
||||
use crate::printer::{Printer, PrinterOptions};
|
||||
|
@ -517,14 +518,12 @@ impl<Context> Format<Context> for () {
|
|||
///
|
||||
/// That's why the `ruff_js_formatter` crate must define a new-type that implements the formatting
|
||||
/// of `JsIfStatement`.
|
||||
pub trait FormatRule<T> {
|
||||
type Context;
|
||||
|
||||
fn fmt(&self, item: &T, f: &mut Formatter<Self::Context>) -> FormatResult<()>;
|
||||
pub trait FormatRule<T, C> {
|
||||
fn fmt(&self, item: &T, f: &mut Formatter<C>) -> FormatResult<()>;
|
||||
}
|
||||
|
||||
/// Rule that supports customizing how it formats an object of type `T`.
|
||||
pub trait FormatRuleWithOptions<T>: FormatRule<T> {
|
||||
pub trait FormatRuleWithOptions<T, C>: FormatRule<T, C> {
|
||||
type Options;
|
||||
|
||||
/// Returns a new rule that uses the given options to format an object.
|
||||
|
@ -564,26 +563,31 @@ pub trait FormatWithRule<Context>: Format<Context> {
|
|||
|
||||
/// Formats the referenced `item` with the specified rule.
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct FormatRefWithRule<'a, T, R>
|
||||
pub struct FormatRefWithRule<'a, T, R, C>
|
||||
where
|
||||
R: FormatRule<T>,
|
||||
R: FormatRule<T, C>,
|
||||
{
|
||||
item: &'a T,
|
||||
rule: R,
|
||||
context: PhantomData<C>,
|
||||
}
|
||||
|
||||
impl<'a, T, R> FormatRefWithRule<'a, T, R>
|
||||
impl<'a, T, R, C> FormatRefWithRule<'a, T, R, C>
|
||||
where
|
||||
R: FormatRule<T>,
|
||||
R: FormatRule<T, C>,
|
||||
{
|
||||
pub fn new(item: &'a T, rule: R) -> Self {
|
||||
Self { item, rule }
|
||||
Self {
|
||||
item,
|
||||
rule,
|
||||
context: PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, R, O> FormatRefWithRule<'_, T, R>
|
||||
impl<T, R, O, C> FormatRefWithRule<'_, T, R, C>
|
||||
where
|
||||
R: FormatRuleWithOptions<T, Options = O>,
|
||||
R: FormatRuleWithOptions<T, C, Options = O>,
|
||||
{
|
||||
pub fn with_options(mut self, options: O) -> Self {
|
||||
self.rule = self.rule.with_options(options);
|
||||
|
@ -591,9 +595,9 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<T, R> FormatWithRule<R::Context> for FormatRefWithRule<'_, T, R>
|
||||
impl<T, R, C> FormatWithRule<C> for FormatRefWithRule<'_, T, R, C>
|
||||
where
|
||||
R: FormatRule<T>,
|
||||
R: FormatRule<T, C>,
|
||||
{
|
||||
type Item = T;
|
||||
|
||||
|
@ -602,32 +606,37 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<T, R> Format<R::Context> for FormatRefWithRule<'_, T, R>
|
||||
impl<T, R, C> Format<C> for FormatRefWithRule<'_, T, R, C>
|
||||
where
|
||||
R: FormatRule<T>,
|
||||
R: FormatRule<T, C>,
|
||||
{
|
||||
#[inline(always)]
|
||||
fn fmt(&self, f: &mut Formatter<R::Context>) -> FormatResult<()> {
|
||||
fn fmt(&self, f: &mut Formatter<C>) -> FormatResult<()> {
|
||||
self.rule.fmt(self.item, f)
|
||||
}
|
||||
}
|
||||
|
||||
/// Formats the `item` with the specified rule.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct FormatOwnedWithRule<T, R>
|
||||
pub struct FormatOwnedWithRule<T, R, C>
|
||||
where
|
||||
R: FormatRule<T>,
|
||||
R: FormatRule<T, C>,
|
||||
{
|
||||
item: T,
|
||||
rule: R,
|
||||
context: PhantomData<C>,
|
||||
}
|
||||
|
||||
impl<T, R> FormatOwnedWithRule<T, R>
|
||||
impl<T, R, C> FormatOwnedWithRule<T, R, C>
|
||||
where
|
||||
R: FormatRule<T>,
|
||||
R: FormatRule<T, C>,
|
||||
{
|
||||
pub fn new(item: T, rule: R) -> Self {
|
||||
Self { item, rule }
|
||||
Self {
|
||||
item,
|
||||
rule,
|
||||
context: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_item(mut self, item: T) -> Self {
|
||||
|
@ -640,19 +649,19 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<T, R> Format<R::Context> for FormatOwnedWithRule<T, R>
|
||||
impl<T, R, C> Format<C> for FormatOwnedWithRule<T, R, C>
|
||||
where
|
||||
R: FormatRule<T>,
|
||||
R: FormatRule<T, C>,
|
||||
{
|
||||
#[inline(always)]
|
||||
fn fmt(&self, f: &mut Formatter<R::Context>) -> FormatResult<()> {
|
||||
fn fmt(&self, f: &mut Formatter<C>) -> FormatResult<()> {
|
||||
self.rule.fmt(&self.item, f)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, R, O> FormatOwnedWithRule<T, R>
|
||||
impl<T, R, O, C> FormatOwnedWithRule<T, R, C>
|
||||
where
|
||||
R: FormatRuleWithOptions<T, Options = O>,
|
||||
R: FormatRuleWithOptions<T, C, Options = O>,
|
||||
{
|
||||
pub fn with_options(mut self, options: O) -> Self {
|
||||
self.rule = self.rule.with_options(options);
|
||||
|
@ -660,9 +669,9 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<T, R> FormatWithRule<R::Context> for FormatOwnedWithRule<T, R>
|
||||
impl<T, R, C> FormatWithRule<C> for FormatOwnedWithRule<T, R, C>
|
||||
where
|
||||
R: FormatRule<T>,
|
||||
R: FormatRule<T, C>,
|
||||
{
|
||||
type Item = T;
|
||||
|
||||
|
|
8
crates/ruff_python_formatter/Docs.md
Normal file
8
crates/ruff_python_formatter/Docs.md
Normal file
|
@ -0,0 +1,8 @@
|
|||
# Rust Python Formatter
|
||||
|
||||
For the formatter, we would like to implement `Format` from the rust_formatter crate for all AST
|
||||
nodes, defined in the rustpython_parser crate. This violates rust's orphan rules. We therefore
|
||||
generate in `generate.py` a newtype for each AST node with implementations of `FormatNodeRule`,
|
||||
`FormatRule`, `AsFormat` and `IntoFormat` on it.
|
||||
|
||||

|
152
crates/ruff_python_formatter/generate.py
Normal file
152
crates/ruff_python_formatter/generate.py
Normal file
|
@ -0,0 +1,152 @@
|
|||
"""See Docs.md"""
|
||||
|
||||
# %%
|
||||
|
||||
import re
|
||||
from collections import defaultdict
|
||||
from pathlib import Path
|
||||
from subprocess import check_output
|
||||
|
||||
|
||||
def rustfmt(code: str) -> str:
|
||||
return check_output(["rustfmt", "--emit=stdout"], input=code, text=True)
|
||||
|
||||
|
||||
# %%
|
||||
# Read nodes
|
||||
|
||||
root = Path(
|
||||
check_output(["git", "rev-parse", "--show-toplevel"], text=True).strip(),
|
||||
)
|
||||
nodes_file = (
|
||||
root.joinpath("crates")
|
||||
.joinpath("ruff_python_ast")
|
||||
.joinpath("src")
|
||||
.joinpath("node.rs")
|
||||
.read_text()
|
||||
)
|
||||
node_lines = (
|
||||
nodes_file.split("pub enum AnyNode {")[1].split("}")[0].strip().splitlines()
|
||||
)
|
||||
nodes = [node_line.split("(")[1].split("<")[0] for node_line in node_lines]
|
||||
print(nodes)
|
||||
|
||||
# %%
|
||||
# Generate newtypes with dummy FormatNodeRule implementations
|
||||
|
||||
out = (
|
||||
root.joinpath("crates")
|
||||
.joinpath("ruff_python_formatter")
|
||||
.joinpath("src")
|
||||
.joinpath("generated.rs")
|
||||
)
|
||||
src = root.joinpath("crates").joinpath("ruff_python_formatter").joinpath("src")
|
||||
|
||||
nodes_grouped = defaultdict(list)
|
||||
# We rename because mod is a keyword in rust
|
||||
groups = {
|
||||
"mod": "module",
|
||||
"expr": "expression",
|
||||
"stmt": "statement",
|
||||
"pattern": "pattern",
|
||||
"other": "other",
|
||||
}
|
||||
|
||||
|
||||
def group_for_node(node: str) -> str:
|
||||
for group in groups:
|
||||
if node.startswith(group.title()):
|
||||
return group
|
||||
else:
|
||||
return "other"
|
||||
|
||||
|
||||
def to_camel_case(node: str) -> str:
|
||||
"""Converts PascalCase to camel_case"""
|
||||
return re.sub("([A-Z])", r"_\1", node).lower().lstrip("_")
|
||||
|
||||
|
||||
for node in nodes:
|
||||
nodes_grouped[group_for_node(node)].append(node)
|
||||
|
||||
for group, group_nodes in nodes_grouped.items():
|
||||
# These conflict with the manually content of the mod.rs files
|
||||
# src.joinpath(groups[group]).mkdir(exist_ok=True)
|
||||
# mod_section = "\n".join(
|
||||
# f"pub(crate) mod {to_camel_case(node)};" for node in group_nodes
|
||||
# )
|
||||
# src.joinpath(groups[group]).joinpath("mod.rs").write_text(rustfmt(mod_section))
|
||||
for node in group_nodes:
|
||||
code = f"""
|
||||
use crate::{{FormatNodeRule, PyFormatter}};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::{node};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Format{node};
|
||||
|
||||
impl FormatNodeRule<{node}> for Format{node} {{
|
||||
fn fmt_fields(&self, _item: &{node}, _f: &mut PyFormatter) -> FormatResult<()> {{
|
||||
Ok(())
|
||||
}}
|
||||
}}
|
||||
""".strip() # noqa: E501
|
||||
src.joinpath(groups[group]).joinpath(f"{to_camel_case(node)}.rs").write_text(
|
||||
rustfmt(code)
|
||||
)
|
||||
|
||||
# %%
|
||||
# Generate `FormatRule`, `AsFormat` and `IntoFormat`
|
||||
|
||||
generated = """//! This is a generated file. Don't modify it by hand! Run `scripts/generate.py` to re-generate the file.
|
||||
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"""
|
||||
impl FormatRule<ast::{node}, PyFormatContext<'_>>
|
||||
for crate::{groups[group_for_node(node)]}::{to_camel_case(node)}::Format{node}
|
||||
{{
|
||||
#[inline]
|
||||
fn fmt(
|
||||
&self,
|
||||
node: &ast::{node},
|
||||
f: &mut Formatter<PyFormatContext<'_>>,
|
||||
) -> FormatResult<()> {{
|
||||
FormatNodeRule::<ast::{node}>::fmt(self, node, f)
|
||||
}}
|
||||
}}
|
||||
impl<'ast> AsFormat<PyFormatContext<'ast>> for ast::{node} {{
|
||||
type Format<'a> = FormatRefWithRule<
|
||||
'a,
|
||||
ast::{node},
|
||||
crate::{groups[group_for_node(node)]}::{to_camel_case(node)}::Format{node},
|
||||
PyFormatContext<'ast>,
|
||||
>;
|
||||
fn format(&self) -> Self::Format<'_> {{
|
||||
FormatRefWithRule::new(
|
||||
self,
|
||||
crate::{groups[group_for_node(node)]}::{to_camel_case(node)}::Format{node}::default(),
|
||||
)
|
||||
}}
|
||||
}}
|
||||
impl<'ast> IntoFormat<PyFormatContext<'ast>> for ast::{node} {{
|
||||
type Format = FormatOwnedWithRule<
|
||||
ast::{node},
|
||||
crate::{groups[group_for_node(node)]}::{to_camel_case(node)}::Format{node},
|
||||
PyFormatContext<'ast>,
|
||||
>;
|
||||
fn into_format(self) -> Self::Format {{
|
||||
FormatOwnedWithRule::new(
|
||||
self,
|
||||
crate::{groups[group_for_node(node)]}::{to_camel_case(node)}::Format{node}::default(),
|
||||
)
|
||||
}}
|
||||
}}
|
||||
""" # noqa: E501
|
||||
generated += text
|
||||
|
||||
out.write_text(rustfmt(generated))
|
File diff suppressed because one or more lines are too long
After Width: | Height: | Size: 19 KiB |
|
@ -4,13 +4,13 @@ use ruff_python_ast::source_code::Locator;
|
|||
use std::fmt::{Debug, Formatter};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ASTFormatContext<'a> {
|
||||
pub struct PyFormatContext<'a> {
|
||||
options: SimpleFormatOptions,
|
||||
contents: &'a str,
|
||||
comments: Comments<'a>,
|
||||
}
|
||||
|
||||
impl<'a> ASTFormatContext<'a> {
|
||||
impl<'a> PyFormatContext<'a> {
|
||||
pub(crate) fn new(
|
||||
options: SimpleFormatOptions,
|
||||
contents: &'a str,
|
||||
|
@ -23,11 +23,13 @@ impl<'a> ASTFormatContext<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn contents(&self) -> &'a str {
|
||||
#[allow(unused)]
|
||||
pub(crate) fn contents(&self) -> &'a str {
|
||||
self.contents
|
||||
}
|
||||
|
||||
pub fn locator(&self) -> Locator<'a> {
|
||||
#[allow(unused)]
|
||||
pub(crate) fn locator(&self) -> Locator<'a> {
|
||||
Locator::new(self.contents)
|
||||
}
|
||||
|
||||
|
@ -37,7 +39,7 @@ impl<'a> ASTFormatContext<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl FormatContext for ASTFormatContext<'_> {
|
||||
impl FormatContext for PyFormatContext<'_> {
|
||||
type Options = SimpleFormatOptions;
|
||||
|
||||
fn options(&self) -> &Self::Options {
|
||||
|
@ -49,9 +51,9 @@ impl FormatContext for ASTFormatContext<'_> {
|
|||
}
|
||||
}
|
||||
|
||||
impl Debug for ASTFormatContext<'_> {
|
||||
impl Debug for PyFormatContext<'_> {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
f.debug_struct("ASTFormatContext")
|
||||
f.debug_struct("PyFormatContext")
|
||||
.field("options", &self.options)
|
||||
.field("comments", &self.comments.debug(self.source_code()))
|
||||
.field("source", &self.contents)
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::ExprAttribute;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatExprAttribute;
|
||||
|
||||
impl FormatNodeRule<ExprAttribute> for FormatExprAttribute {
|
||||
fn fmt_fields(&self, _item: &ExprAttribute, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
12
crates/ruff_python_formatter/src/expression/expr_await.rs
Normal file
12
crates/ruff_python_formatter/src/expression/expr_await.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::ExprAwait;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatExprAwait;
|
||||
|
||||
impl FormatNodeRule<ExprAwait> for FormatExprAwait {
|
||||
fn fmt_fields(&self, _item: &ExprAwait, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
12
crates/ruff_python_formatter/src/expression/expr_bin_op.rs
Normal file
12
crates/ruff_python_formatter/src/expression/expr_bin_op.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::ExprBinOp;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatExprBinOp;
|
||||
|
||||
impl FormatNodeRule<ExprBinOp> for FormatExprBinOp {
|
||||
fn fmt_fields(&self, _item: &ExprBinOp, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
12
crates/ruff_python_formatter/src/expression/expr_bool_op.rs
Normal file
12
crates/ruff_python_formatter/src/expression/expr_bool_op.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::ExprBoolOp;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatExprBoolOp;
|
||||
|
||||
impl FormatNodeRule<ExprBoolOp> for FormatExprBoolOp {
|
||||
fn fmt_fields(&self, _item: &ExprBoolOp, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
12
crates/ruff_python_formatter/src/expression/expr_call.rs
Normal file
12
crates/ruff_python_formatter/src/expression/expr_call.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::ExprCall;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatExprCall;
|
||||
|
||||
impl FormatNodeRule<ExprCall> for FormatExprCall {
|
||||
fn fmt_fields(&self, _item: &ExprCall, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
12
crates/ruff_python_formatter/src/expression/expr_compare.rs
Normal file
12
crates/ruff_python_formatter/src/expression/expr_compare.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::ExprCompare;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatExprCompare;
|
||||
|
||||
impl FormatNodeRule<ExprCompare> for FormatExprCompare {
|
||||
fn fmt_fields(&self, _item: &ExprCompare, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
12
crates/ruff_python_formatter/src/expression/expr_constant.rs
Normal file
12
crates/ruff_python_formatter/src/expression/expr_constant.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::ExprConstant;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatExprConstant;
|
||||
|
||||
impl FormatNodeRule<ExprConstant> for FormatExprConstant {
|
||||
fn fmt_fields(&self, _item: &ExprConstant, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
12
crates/ruff_python_formatter/src/expression/expr_dict.rs
Normal file
12
crates/ruff_python_formatter/src/expression/expr_dict.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::ExprDict;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatExprDict;
|
||||
|
||||
impl FormatNodeRule<ExprDict> for FormatExprDict {
|
||||
fn fmt_fields(&self, _item: &ExprDict, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::ExprDictComp;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatExprDictComp;
|
||||
|
||||
impl FormatNodeRule<ExprDictComp> for FormatExprDictComp {
|
||||
fn fmt_fields(&self, _item: &ExprDictComp, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::ExprFormattedValue;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatExprFormattedValue;
|
||||
|
||||
impl FormatNodeRule<ExprFormattedValue> for FormatExprFormattedValue {
|
||||
fn fmt_fields(&self, _item: &ExprFormattedValue, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::ExprGeneratorExp;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatExprGeneratorExp;
|
||||
|
||||
impl FormatNodeRule<ExprGeneratorExp> for FormatExprGeneratorExp {
|
||||
fn fmt_fields(&self, _item: &ExprGeneratorExp, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
12
crates/ruff_python_formatter/src/expression/expr_if_exp.rs
Normal file
12
crates/ruff_python_formatter/src/expression/expr_if_exp.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::ExprIfExp;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatExprIfExp;
|
||||
|
||||
impl FormatNodeRule<ExprIfExp> for FormatExprIfExp {
|
||||
fn fmt_fields(&self, _item: &ExprIfExp, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::ExprJoinedStr;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatExprJoinedStr;
|
||||
|
||||
impl FormatNodeRule<ExprJoinedStr> for FormatExprJoinedStr {
|
||||
fn fmt_fields(&self, _item: &ExprJoinedStr, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
12
crates/ruff_python_formatter/src/expression/expr_lambda.rs
Normal file
12
crates/ruff_python_formatter/src/expression/expr_lambda.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::ExprLambda;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatExprLambda;
|
||||
|
||||
impl FormatNodeRule<ExprLambda> for FormatExprLambda {
|
||||
fn fmt_fields(&self, _item: &ExprLambda, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
12
crates/ruff_python_formatter/src/expression/expr_list.rs
Normal file
12
crates/ruff_python_formatter/src/expression/expr_list.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::ExprList;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatExprList;
|
||||
|
||||
impl FormatNodeRule<ExprList> for FormatExprList {
|
||||
fn fmt_fields(&self, _item: &ExprList, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::ExprListComp;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatExprListComp;
|
||||
|
||||
impl FormatNodeRule<ExprListComp> for FormatExprListComp {
|
||||
fn fmt_fields(&self, _item: &ExprListComp, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
12
crates/ruff_python_formatter/src/expression/expr_name.rs
Normal file
12
crates/ruff_python_formatter/src/expression/expr_name.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::ExprName;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatExprName;
|
||||
|
||||
impl FormatNodeRule<ExprName> for FormatExprName {
|
||||
fn fmt_fields(&self, _item: &ExprName, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::ExprNamedExpr;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatExprNamedExpr;
|
||||
|
||||
impl FormatNodeRule<ExprNamedExpr> for FormatExprNamedExpr {
|
||||
fn fmt_fields(&self, _item: &ExprNamedExpr, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
12
crates/ruff_python_formatter/src/expression/expr_set.rs
Normal file
12
crates/ruff_python_formatter/src/expression/expr_set.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::ExprSet;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatExprSet;
|
||||
|
||||
impl FormatNodeRule<ExprSet> for FormatExprSet {
|
||||
fn fmt_fields(&self, _item: &ExprSet, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
12
crates/ruff_python_formatter/src/expression/expr_set_comp.rs
Normal file
12
crates/ruff_python_formatter/src/expression/expr_set_comp.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::ExprSetComp;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatExprSetComp;
|
||||
|
||||
impl FormatNodeRule<ExprSetComp> for FormatExprSetComp {
|
||||
fn fmt_fields(&self, _item: &ExprSetComp, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
12
crates/ruff_python_formatter/src/expression/expr_slice.rs
Normal file
12
crates/ruff_python_formatter/src/expression/expr_slice.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::ExprSlice;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatExprSlice;
|
||||
|
||||
impl FormatNodeRule<ExprSlice> for FormatExprSlice {
|
||||
fn fmt_fields(&self, _item: &ExprSlice, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
12
crates/ruff_python_formatter/src/expression/expr_starred.rs
Normal file
12
crates/ruff_python_formatter/src/expression/expr_starred.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::ExprStarred;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatExprStarred;
|
||||
|
||||
impl FormatNodeRule<ExprStarred> for FormatExprStarred {
|
||||
fn fmt_fields(&self, _item: &ExprStarred, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::ExprSubscript;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatExprSubscript;
|
||||
|
||||
impl FormatNodeRule<ExprSubscript> for FormatExprSubscript {
|
||||
fn fmt_fields(&self, _item: &ExprSubscript, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
12
crates/ruff_python_formatter/src/expression/expr_tuple.rs
Normal file
12
crates/ruff_python_formatter/src/expression/expr_tuple.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::ExprTuple;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatExprTuple;
|
||||
|
||||
impl FormatNodeRule<ExprTuple> for FormatExprTuple {
|
||||
fn fmt_fields(&self, _item: &ExprTuple, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
12
crates/ruff_python_formatter/src/expression/expr_unary_op.rs
Normal file
12
crates/ruff_python_formatter/src/expression/expr_unary_op.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::ExprUnaryOp;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatExprUnaryOp;
|
||||
|
||||
impl FormatNodeRule<ExprUnaryOp> for FormatExprUnaryOp {
|
||||
fn fmt_fields(&self, _item: &ExprUnaryOp, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
12
crates/ruff_python_formatter/src/expression/expr_yield.rs
Normal file
12
crates/ruff_python_formatter/src/expression/expr_yield.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::ExprYield;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatExprYield;
|
||||
|
||||
impl FormatNodeRule<ExprYield> for FormatExprYield {
|
||||
fn fmt_fields(&self, _item: &ExprYield, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::ExprYieldFrom;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatExprYieldFrom;
|
||||
|
||||
impl FormatNodeRule<ExprYieldFrom> for FormatExprYieldFrom {
|
||||
fn fmt_fields(&self, _item: &ExprYieldFrom, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
27
crates/ruff_python_formatter/src/expression/mod.rs
Normal file
27
crates/ruff_python_formatter/src/expression/mod.rs
Normal file
|
@ -0,0 +1,27 @@
|
|||
pub(crate) mod expr_attribute;
|
||||
pub(crate) mod expr_await;
|
||||
pub(crate) mod expr_bin_op;
|
||||
pub(crate) mod expr_bool_op;
|
||||
pub(crate) mod expr_call;
|
||||
pub(crate) mod expr_compare;
|
||||
pub(crate) mod expr_constant;
|
||||
pub(crate) mod expr_dict;
|
||||
pub(crate) mod expr_dict_comp;
|
||||
pub(crate) mod expr_formatted_value;
|
||||
pub(crate) mod expr_generator_exp;
|
||||
pub(crate) mod expr_if_exp;
|
||||
pub(crate) mod expr_joined_str;
|
||||
pub(crate) mod expr_lambda;
|
||||
pub(crate) mod expr_list;
|
||||
pub(crate) mod expr_list_comp;
|
||||
pub(crate) mod expr_name;
|
||||
pub(crate) mod expr_named_expr;
|
||||
pub(crate) mod expr_set;
|
||||
pub(crate) mod expr_set_comp;
|
||||
pub(crate) mod expr_slice;
|
||||
pub(crate) mod expr_starred;
|
||||
pub(crate) mod expr_subscript;
|
||||
pub(crate) mod expr_tuple;
|
||||
pub(crate) mod expr_unary_op;
|
||||
pub(crate) mod expr_yield;
|
||||
pub(crate) mod expr_yield_from;
|
2860
crates/ruff_python_formatter/src/generated.rs
Normal file
2860
crates/ruff_python_formatter/src/generated.rs
Normal file
File diff suppressed because it is too large
Load diff
|
@ -3,23 +3,86 @@ use rustpython_parser::ast::Mod;
|
|||
use rustpython_parser::lexer::lex;
|
||||
use rustpython_parser::{parse_tokens, Mode};
|
||||
|
||||
use ruff_formatter::formatter::Formatter;
|
||||
use ruff_formatter::prelude::source_position;
|
||||
use ruff_formatter::{
|
||||
format, FormatResult, Formatted, IndentStyle, Printed, SimpleFormatOptions, SourceCode,
|
||||
format, write, Buffer, FormatResult, Formatted, IndentStyle, Printed, SimpleFormatOptions,
|
||||
SourceCode,
|
||||
};
|
||||
use ruff_python_ast::node::AstNode;
|
||||
use ruff_python_ast::source_code::{CommentRanges, CommentRangesBuilder, Locator};
|
||||
|
||||
use crate::comments::Comments;
|
||||
use crate::context::ASTFormatContext;
|
||||
use crate::context::PyFormatContext;
|
||||
use crate::module::FormatModule;
|
||||
|
||||
pub mod cli;
|
||||
mod comments;
|
||||
pub mod context;
|
||||
mod module;
|
||||
pub(crate) mod context;
|
||||
pub(crate) mod expression;
|
||||
mod generated;
|
||||
pub(crate) mod module;
|
||||
pub(crate) mod other;
|
||||
pub(crate) mod pattern;
|
||||
mod prelude;
|
||||
pub(crate) mod statement;
|
||||
|
||||
include!("../../ruff_formatter/shared_traits.rs");
|
||||
|
||||
pub(crate) type PyFormatter<'buf, 'ast> = Formatter<'buf, PyFormatContext<'ast>>;
|
||||
|
||||
/// Rule for formatting a JavaScript [`AstNode`].
|
||||
pub(crate) trait FormatNodeRule<N>
|
||||
where
|
||||
N: AstNode,
|
||||
{
|
||||
fn fmt(&self, node: &N, f: &mut PyFormatter) -> FormatResult<()> {
|
||||
write!(f, [source_position(node.start())])?;
|
||||
self.fmt_leading_comments(node, f)?;
|
||||
self.fmt_node(node, f)?;
|
||||
self.fmt_dangling_comments(node, f)?;
|
||||
self.fmt_trailing_comments(node, f)?;
|
||||
write!(f, [source_position(node.start())])
|
||||
}
|
||||
|
||||
/// Formats the node without comments. Ignores any suppression comments.
|
||||
fn fmt_node(&self, node: &N, f: &mut PyFormatter) -> FormatResult<()> {
|
||||
self.fmt_fields(node, f)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Formats the node's fields.
|
||||
fn fmt_fields(&self, item: &N, f: &mut PyFormatter) -> FormatResult<()>;
|
||||
|
||||
/// Formats the [leading comments](crate::comments#leading-comments) of the node.
|
||||
///
|
||||
/// You may want to override this method if you want to manually handle the formatting of comments
|
||||
/// inside of the `fmt_fields` method or customize the formatting of the leading comments.
|
||||
fn fmt_leading_comments(&self, _node: &N, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Formats the [dangling comments](rome_formatter::comments#dangling-comments) of the node.
|
||||
///
|
||||
/// You should override this method if the node handled by this rule can have dangling comments because the
|
||||
/// default implementation formats the dangling comments at the end of the node, which isn't ideal but ensures that
|
||||
/// no comments are dropped.
|
||||
///
|
||||
/// A node can have dangling comments if all its children are tokens or if all node childrens are optional.
|
||||
fn fmt_dangling_comments(&self, _node: &N, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Formats the [trailing comments](rome_formatter::comments#trailing-comments) of the node.
|
||||
///
|
||||
/// You may want to override this method if you want to manually handle the formatting of comments
|
||||
/// inside of the `fmt_fields` method or customize the formatting of the trailing comments.
|
||||
fn fmt_trailing_comments(&self, _node: &N, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn format_module(contents: &str) -> Result<Printed> {
|
||||
// Tokenize once
|
||||
let mut tokens = Vec::new();
|
||||
|
@ -52,13 +115,13 @@ pub fn format_node<'a>(
|
|||
root: &'a Mod,
|
||||
comment_ranges: &'a CommentRanges,
|
||||
source: &'a str,
|
||||
) -> FormatResult<Formatted<ASTFormatContext<'a>>> {
|
||||
) -> FormatResult<Formatted<PyFormatContext<'a>>> {
|
||||
let comments = Comments::from_ast(root, SourceCode::new(source), comment_ranges);
|
||||
|
||||
let locator = Locator::new(source);
|
||||
|
||||
format!(
|
||||
ASTFormatContext::new(
|
||||
PyFormatContext::new(
|
||||
SimpleFormatOptions {
|
||||
indent_style: IndentStyle::Space(4),
|
||||
line_width: 88.try_into().unwrap(),
|
||||
|
|
|
@ -1,4 +1,9 @@
|
|||
use crate::context::ASTFormatContext;
|
||||
pub(crate) mod mod_expression;
|
||||
pub(crate) mod mod_function_type;
|
||||
pub(crate) mod mod_interactive;
|
||||
pub(crate) mod mod_module;
|
||||
|
||||
use crate::context::PyFormatContext;
|
||||
use ruff_formatter::format_element::tag::VerbatimKind;
|
||||
use ruff_formatter::prelude::*;
|
||||
use ruff_formatter::write;
|
||||
|
@ -14,8 +19,8 @@ impl<'a> FormatModule<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl Format<ASTFormatContext<'_>> for FormatModule<'_> {
|
||||
fn fmt(&self, f: &mut Formatter<ASTFormatContext<'_>>) -> FormatResult<()> {
|
||||
impl Format<PyFormatContext<'_>> for FormatModule<'_> {
|
||||
fn fmt(&self, f: &mut Formatter<PyFormatContext<'_>>) -> FormatResult<()> {
|
||||
let range = self.module.range();
|
||||
|
||||
write!(f, [source_position(range.start())])?;
|
||||
|
|
12
crates/ruff_python_formatter/src/module/mod_expression.rs
Normal file
12
crates/ruff_python_formatter/src/module/mod_expression.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::ModExpression;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatModExpression;
|
||||
|
||||
impl FormatNodeRule<ModExpression> for FormatModExpression {
|
||||
fn fmt_fields(&self, _item: &ModExpression, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
12
crates/ruff_python_formatter/src/module/mod_function_type.rs
Normal file
12
crates/ruff_python_formatter/src/module/mod_function_type.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::ModFunctionType;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatModFunctionType;
|
||||
|
||||
impl FormatNodeRule<ModFunctionType> for FormatModFunctionType {
|
||||
fn fmt_fields(&self, _item: &ModFunctionType, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
12
crates/ruff_python_formatter/src/module/mod_interactive.rs
Normal file
12
crates/ruff_python_formatter/src/module/mod_interactive.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::ModInteractive;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatModInteractive;
|
||||
|
||||
impl FormatNodeRule<ModInteractive> for FormatModInteractive {
|
||||
fn fmt_fields(&self, _item: &ModInteractive, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
12
crates/ruff_python_formatter/src/module/mod_module.rs
Normal file
12
crates/ruff_python_formatter/src/module/mod_module.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::ModModule;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatModModule;
|
||||
|
||||
impl FormatNodeRule<ModModule> for FormatModModule {
|
||||
fn fmt_fields(&self, _item: &ModModule, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
12
crates/ruff_python_formatter/src/other/alias.rs
Normal file
12
crates/ruff_python_formatter/src/other/alias.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::Alias;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatAlias;
|
||||
|
||||
impl FormatNodeRule<Alias> for FormatAlias {
|
||||
fn fmt_fields(&self, _item: &Alias, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
12
crates/ruff_python_formatter/src/other/arg.rs
Normal file
12
crates/ruff_python_formatter/src/other/arg.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::Arg;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatArg;
|
||||
|
||||
impl FormatNodeRule<Arg> for FormatArg {
|
||||
fn fmt_fields(&self, _item: &Arg, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
12
crates/ruff_python_formatter/src/other/arguments.rs
Normal file
12
crates/ruff_python_formatter/src/other/arguments.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::Arguments;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatArguments;
|
||||
|
||||
impl FormatNodeRule<Arguments> for FormatArguments {
|
||||
fn fmt_fields(&self, _item: &Arguments, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
12
crates/ruff_python_formatter/src/other/comprehension.rs
Normal file
12
crates/ruff_python_formatter/src/other/comprehension.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::Comprehension;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatComprehension;
|
||||
|
||||
impl FormatNodeRule<Comprehension> for FormatComprehension {
|
||||
fn fmt_fields(&self, _item: &Comprehension, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::ExcepthandlerExceptHandler;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatExcepthandlerExceptHandler;
|
||||
|
||||
impl FormatNodeRule<ExcepthandlerExceptHandler> for FormatExcepthandlerExceptHandler {
|
||||
fn fmt_fields(
|
||||
&self,
|
||||
_item: &ExcepthandlerExceptHandler,
|
||||
_f: &mut PyFormatter,
|
||||
) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
12
crates/ruff_python_formatter/src/other/keyword.rs
Normal file
12
crates/ruff_python_formatter/src/other/keyword.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::Keyword;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatKeyword;
|
||||
|
||||
impl FormatNodeRule<Keyword> for FormatKeyword {
|
||||
fn fmt_fields(&self, _item: &Keyword, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
12
crates/ruff_python_formatter/src/other/match_case.rs
Normal file
12
crates/ruff_python_formatter/src/other/match_case.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::MatchCase;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatMatchCase;
|
||||
|
||||
impl FormatNodeRule<MatchCase> for FormatMatchCase {
|
||||
fn fmt_fields(&self, _item: &MatchCase, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
9
crates/ruff_python_formatter/src/other/mod.rs
Normal file
9
crates/ruff_python_formatter/src/other/mod.rs
Normal file
|
@ -0,0 +1,9 @@
|
|||
pub(crate) mod alias;
|
||||
pub(crate) mod arg;
|
||||
pub(crate) mod arguments;
|
||||
pub(crate) mod comprehension;
|
||||
pub(crate) mod excepthandler_except_handler;
|
||||
pub(crate) mod keyword;
|
||||
pub(crate) mod match_case;
|
||||
pub(crate) mod type_ignore_type_ignore;
|
||||
pub(crate) mod withitem;
|
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::TypeIgnoreTypeIgnore;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatTypeIgnoreTypeIgnore;
|
||||
|
||||
impl FormatNodeRule<TypeIgnoreTypeIgnore> for FormatTypeIgnoreTypeIgnore {
|
||||
fn fmt_fields(&self, _item: &TypeIgnoreTypeIgnore, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
12
crates/ruff_python_formatter/src/other/withitem.rs
Normal file
12
crates/ruff_python_formatter/src/other/withitem.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::Withitem;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatWithitem;
|
||||
|
||||
impl FormatNodeRule<Withitem> for FormatWithitem {
|
||||
fn fmt_fields(&self, _item: &Withitem, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
8
crates/ruff_python_formatter/src/pattern/mod.rs
Normal file
8
crates/ruff_python_formatter/src/pattern/mod.rs
Normal file
|
@ -0,0 +1,8 @@
|
|||
pub(crate) mod pattern_match_as;
|
||||
pub(crate) mod pattern_match_class;
|
||||
pub(crate) mod pattern_match_mapping;
|
||||
pub(crate) mod pattern_match_or;
|
||||
pub(crate) mod pattern_match_sequence;
|
||||
pub(crate) mod pattern_match_singleton;
|
||||
pub(crate) mod pattern_match_star;
|
||||
pub(crate) mod pattern_match_value;
|
12
crates/ruff_python_formatter/src/pattern/pattern_match_as.rs
Normal file
12
crates/ruff_python_formatter/src/pattern/pattern_match_as.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::PatternMatchAs;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatPatternMatchAs;
|
||||
|
||||
impl FormatNodeRule<PatternMatchAs> for FormatPatternMatchAs {
|
||||
fn fmt_fields(&self, _item: &PatternMatchAs, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::PatternMatchClass;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatPatternMatchClass;
|
||||
|
||||
impl FormatNodeRule<PatternMatchClass> for FormatPatternMatchClass {
|
||||
fn fmt_fields(&self, _item: &PatternMatchClass, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::PatternMatchMapping;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatPatternMatchMapping;
|
||||
|
||||
impl FormatNodeRule<PatternMatchMapping> for FormatPatternMatchMapping {
|
||||
fn fmt_fields(&self, _item: &PatternMatchMapping, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
12
crates/ruff_python_formatter/src/pattern/pattern_match_or.rs
Normal file
12
crates/ruff_python_formatter/src/pattern/pattern_match_or.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::PatternMatchOr;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatPatternMatchOr;
|
||||
|
||||
impl FormatNodeRule<PatternMatchOr> for FormatPatternMatchOr {
|
||||
fn fmt_fields(&self, _item: &PatternMatchOr, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::PatternMatchSequence;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatPatternMatchSequence;
|
||||
|
||||
impl FormatNodeRule<PatternMatchSequence> for FormatPatternMatchSequence {
|
||||
fn fmt_fields(&self, _item: &PatternMatchSequence, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::PatternMatchSingleton;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatPatternMatchSingleton;
|
||||
|
||||
impl FormatNodeRule<PatternMatchSingleton> for FormatPatternMatchSingleton {
|
||||
fn fmt_fields(&self, _item: &PatternMatchSingleton, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::PatternMatchStar;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatPatternMatchStar;
|
||||
|
||||
impl FormatNodeRule<PatternMatchStar> for FormatPatternMatchStar {
|
||||
fn fmt_fields(&self, _item: &PatternMatchStar, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::PatternMatchValue;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatPatternMatchValue;
|
||||
|
||||
impl FormatNodeRule<PatternMatchValue> for FormatPatternMatchValue {
|
||||
fn fmt_fields(&self, _item: &PatternMatchValue, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
#[allow(unused_imports)]
|
||||
pub(crate) use crate::{ASTFormatContext, AsFormat, FormattedIterExt as _, IntoFormat};
|
||||
pub(crate) use crate::{AsFormat, FormattedIterExt as _, IntoFormat, PyFormatContext};
|
||||
#[allow(unused_imports)]
|
||||
pub(crate) use ruff_formatter::prelude::*;
|
||||
|
|
27
crates/ruff_python_formatter/src/statement/mod.rs
Normal file
27
crates/ruff_python_formatter/src/statement/mod.rs
Normal file
|
@ -0,0 +1,27 @@
|
|||
pub(crate) mod stmt_ann_assign;
|
||||
pub(crate) mod stmt_assert;
|
||||
pub(crate) mod stmt_assign;
|
||||
pub(crate) mod stmt_async_for;
|
||||
pub(crate) mod stmt_async_function_def;
|
||||
pub(crate) mod stmt_async_with;
|
||||
pub(crate) mod stmt_aug_assign;
|
||||
pub(crate) mod stmt_break;
|
||||
pub(crate) mod stmt_class_def;
|
||||
pub(crate) mod stmt_continue;
|
||||
pub(crate) mod stmt_delete;
|
||||
pub(crate) mod stmt_expr;
|
||||
pub(crate) mod stmt_for;
|
||||
pub(crate) mod stmt_function_def;
|
||||
pub(crate) mod stmt_global;
|
||||
pub(crate) mod stmt_if;
|
||||
pub(crate) mod stmt_import;
|
||||
pub(crate) mod stmt_import_from;
|
||||
pub(crate) mod stmt_match;
|
||||
pub(crate) mod stmt_nonlocal;
|
||||
pub(crate) mod stmt_pass;
|
||||
pub(crate) mod stmt_raise;
|
||||
pub(crate) mod stmt_return;
|
||||
pub(crate) mod stmt_try;
|
||||
pub(crate) mod stmt_try_star;
|
||||
pub(crate) mod stmt_while;
|
||||
pub(crate) mod stmt_with;
|
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::StmtAnnAssign;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatStmtAnnAssign;
|
||||
|
||||
impl FormatNodeRule<StmtAnnAssign> for FormatStmtAnnAssign {
|
||||
fn fmt_fields(&self, _item: &StmtAnnAssign, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
12
crates/ruff_python_formatter/src/statement/stmt_assert.rs
Normal file
12
crates/ruff_python_formatter/src/statement/stmt_assert.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::StmtAssert;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatStmtAssert;
|
||||
|
||||
impl FormatNodeRule<StmtAssert> for FormatStmtAssert {
|
||||
fn fmt_fields(&self, _item: &StmtAssert, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
12
crates/ruff_python_formatter/src/statement/stmt_assign.rs
Normal file
12
crates/ruff_python_formatter/src/statement/stmt_assign.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::StmtAssign;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatStmtAssign;
|
||||
|
||||
impl FormatNodeRule<StmtAssign> for FormatStmtAssign {
|
||||
fn fmt_fields(&self, _item: &StmtAssign, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
12
crates/ruff_python_formatter/src/statement/stmt_async_for.rs
Normal file
12
crates/ruff_python_formatter/src/statement/stmt_async_for.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::StmtAsyncFor;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatStmtAsyncFor;
|
||||
|
||||
impl FormatNodeRule<StmtAsyncFor> for FormatStmtAsyncFor {
|
||||
fn fmt_fields(&self, _item: &StmtAsyncFor, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::StmtAsyncFunctionDef;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatStmtAsyncFunctionDef;
|
||||
|
||||
impl FormatNodeRule<StmtAsyncFunctionDef> for FormatStmtAsyncFunctionDef {
|
||||
fn fmt_fields(&self, _item: &StmtAsyncFunctionDef, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::StmtAsyncWith;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatStmtAsyncWith;
|
||||
|
||||
impl FormatNodeRule<StmtAsyncWith> for FormatStmtAsyncWith {
|
||||
fn fmt_fields(&self, _item: &StmtAsyncWith, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::StmtAugAssign;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatStmtAugAssign;
|
||||
|
||||
impl FormatNodeRule<StmtAugAssign> for FormatStmtAugAssign {
|
||||
fn fmt_fields(&self, _item: &StmtAugAssign, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
12
crates/ruff_python_formatter/src/statement/stmt_break.rs
Normal file
12
crates/ruff_python_formatter/src/statement/stmt_break.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::StmtBreak;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatStmtBreak;
|
||||
|
||||
impl FormatNodeRule<StmtBreak> for FormatStmtBreak {
|
||||
fn fmt_fields(&self, _item: &StmtBreak, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
12
crates/ruff_python_formatter/src/statement/stmt_class_def.rs
Normal file
12
crates/ruff_python_formatter/src/statement/stmt_class_def.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::StmtClassDef;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatStmtClassDef;
|
||||
|
||||
impl FormatNodeRule<StmtClassDef> for FormatStmtClassDef {
|
||||
fn fmt_fields(&self, _item: &StmtClassDef, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
12
crates/ruff_python_formatter/src/statement/stmt_continue.rs
Normal file
12
crates/ruff_python_formatter/src/statement/stmt_continue.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::StmtContinue;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatStmtContinue;
|
||||
|
||||
impl FormatNodeRule<StmtContinue> for FormatStmtContinue {
|
||||
fn fmt_fields(&self, _item: &StmtContinue, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
12
crates/ruff_python_formatter/src/statement/stmt_delete.rs
Normal file
12
crates/ruff_python_formatter/src/statement/stmt_delete.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::StmtDelete;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatStmtDelete;
|
||||
|
||||
impl FormatNodeRule<StmtDelete> for FormatStmtDelete {
|
||||
fn fmt_fields(&self, _item: &StmtDelete, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
12
crates/ruff_python_formatter/src/statement/stmt_expr.rs
Normal file
12
crates/ruff_python_formatter/src/statement/stmt_expr.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::StmtExpr;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatStmtExpr;
|
||||
|
||||
impl FormatNodeRule<StmtExpr> for FormatStmtExpr {
|
||||
fn fmt_fields(&self, _item: &StmtExpr, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
12
crates/ruff_python_formatter/src/statement/stmt_for.rs
Normal file
12
crates/ruff_python_formatter/src/statement/stmt_for.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::StmtFor;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatStmtFor;
|
||||
|
||||
impl FormatNodeRule<StmtFor> for FormatStmtFor {
|
||||
fn fmt_fields(&self, _item: &StmtFor, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::StmtFunctionDef;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatStmtFunctionDef;
|
||||
|
||||
impl FormatNodeRule<StmtFunctionDef> for FormatStmtFunctionDef {
|
||||
fn fmt_fields(&self, _item: &StmtFunctionDef, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
12
crates/ruff_python_formatter/src/statement/stmt_global.rs
Normal file
12
crates/ruff_python_formatter/src/statement/stmt_global.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::StmtGlobal;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatStmtGlobal;
|
||||
|
||||
impl FormatNodeRule<StmtGlobal> for FormatStmtGlobal {
|
||||
fn fmt_fields(&self, _item: &StmtGlobal, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
12
crates/ruff_python_formatter/src/statement/stmt_if.rs
Normal file
12
crates/ruff_python_formatter/src/statement/stmt_if.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::StmtIf;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatStmtIf;
|
||||
|
||||
impl FormatNodeRule<StmtIf> for FormatStmtIf {
|
||||
fn fmt_fields(&self, _item: &StmtIf, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
12
crates/ruff_python_formatter/src/statement/stmt_import.rs
Normal file
12
crates/ruff_python_formatter/src/statement/stmt_import.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::StmtImport;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatStmtImport;
|
||||
|
||||
impl FormatNodeRule<StmtImport> for FormatStmtImport {
|
||||
fn fmt_fields(&self, _item: &StmtImport, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::StmtImportFrom;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatStmtImportFrom;
|
||||
|
||||
impl FormatNodeRule<StmtImportFrom> for FormatStmtImportFrom {
|
||||
fn fmt_fields(&self, _item: &StmtImportFrom, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
12
crates/ruff_python_formatter/src/statement/stmt_match.rs
Normal file
12
crates/ruff_python_formatter/src/statement/stmt_match.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::StmtMatch;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatStmtMatch;
|
||||
|
||||
impl FormatNodeRule<StmtMatch> for FormatStmtMatch {
|
||||
fn fmt_fields(&self, _item: &StmtMatch, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
12
crates/ruff_python_formatter/src/statement/stmt_nonlocal.rs
Normal file
12
crates/ruff_python_formatter/src/statement/stmt_nonlocal.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::StmtNonlocal;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatStmtNonlocal;
|
||||
|
||||
impl FormatNodeRule<StmtNonlocal> for FormatStmtNonlocal {
|
||||
fn fmt_fields(&self, _item: &StmtNonlocal, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
12
crates/ruff_python_formatter/src/statement/stmt_pass.rs
Normal file
12
crates/ruff_python_formatter/src/statement/stmt_pass.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::StmtPass;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatStmtPass;
|
||||
|
||||
impl FormatNodeRule<StmtPass> for FormatStmtPass {
|
||||
fn fmt_fields(&self, _item: &StmtPass, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
12
crates/ruff_python_formatter/src/statement/stmt_raise.rs
Normal file
12
crates/ruff_python_formatter/src/statement/stmt_raise.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::StmtRaise;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatStmtRaise;
|
||||
|
||||
impl FormatNodeRule<StmtRaise> for FormatStmtRaise {
|
||||
fn fmt_fields(&self, _item: &StmtRaise, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
12
crates/ruff_python_formatter/src/statement/stmt_return.rs
Normal file
12
crates/ruff_python_formatter/src/statement/stmt_return.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::StmtReturn;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatStmtReturn;
|
||||
|
||||
impl FormatNodeRule<StmtReturn> for FormatStmtReturn {
|
||||
fn fmt_fields(&self, _item: &StmtReturn, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
12
crates/ruff_python_formatter/src/statement/stmt_try.rs
Normal file
12
crates/ruff_python_formatter/src/statement/stmt_try.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::StmtTry;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatStmtTry;
|
||||
|
||||
impl FormatNodeRule<StmtTry> for FormatStmtTry {
|
||||
fn fmt_fields(&self, _item: &StmtTry, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
12
crates/ruff_python_formatter/src/statement/stmt_try_star.rs
Normal file
12
crates/ruff_python_formatter/src/statement/stmt_try_star.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::StmtTryStar;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatStmtTryStar;
|
||||
|
||||
impl FormatNodeRule<StmtTryStar> for FormatStmtTryStar {
|
||||
fn fmt_fields(&self, _item: &StmtTryStar, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
12
crates/ruff_python_formatter/src/statement/stmt_while.rs
Normal file
12
crates/ruff_python_formatter/src/statement/stmt_while.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::StmtWhile;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatStmtWhile;
|
||||
|
||||
impl FormatNodeRule<StmtWhile> for FormatStmtWhile {
|
||||
fn fmt_fields(&self, _item: &StmtWhile, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
12
crates/ruff_python_formatter/src/statement/stmt_with.rs
Normal file
12
crates/ruff_python_formatter/src/statement/stmt_with.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::FormatResult;
|
||||
use rustpython_parser::ast::StmtWith;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatStmtWith;
|
||||
|
||||
impl FormatNodeRule<StmtWith> for FormatStmtWith {
|
||||
fn fmt_fields(&self, _item: &StmtWith, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue