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:
konstin 2023-06-01 08:38:53 +02:00 committed by GitHub
parent b7294b48e7
commit 0945803427
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
88 changed files with 4136 additions and 46 deletions

View file

@ -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)