mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-23 03:45:14 +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
|
@ -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(())
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue