Skip to content

Commit

Permalink
refactor(ruff_fmt): Replace rome_rowan dependency with `rome_text_s…
Browse files Browse the repository at this point in the history
…ize` (#2)

Remove the `rome_rowan` dependency from `ruff_fmt` and use `rome_text_size` directly.

This is just an aesthetic cleanup that does not improve compile time because `ruff_fmt` depends on `rome_formatter` which depends on `rome_rowan`.
  • Loading branch information
MichaReiser authored and charliermarsh committed Feb 15, 2023
1 parent e60710d commit 3c4fd73
Show file tree
Hide file tree
Showing 9 changed files with 8 additions and 38 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/ruff_fmt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ clap = { version = "4.0.1", features = ["derive"] }
insta = { version = "1.19.1", features = ["yaml"] }
once_cell = "1.17.0"
rome_formatter = { path = "../../../tools/crates/rome_formatter" }
rome_rowan = { path = "../../../tools/crates/rome_rowan" }
rome_text_size = { path = "../../../tools/crates/rome_text_size" }
rustc-hash = "1.1.0"
rustpython-ast = { git = "https://github.com/RustPython/RustPython.git", rev = "4f38cb68e4a97aeea9eb19673803a0bd5f655383" }
rustpython-common = { git = "https://github.com/RustPython/RustPython.git", rev = "4f38cb68e4a97aeea9eb19673803a0bd5f655383" }
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff_fmt/src/format/alias.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use rome_formatter::prelude::*;
use rome_formatter::write;
use rome_rowan::TextSize;
use rome_text_size::TextSize;

use crate::context::ASTFormatContext;
use crate::cst::Alias;
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff_fmt/src/format/arg.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use rome_formatter::prelude::*;
use rome_formatter::write;
use rome_rowan::TextSize;
use rome_text_size::TextSize;

use crate::context::ASTFormatContext;
use crate::cst::Arg;
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff_fmt/src/format/builders.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use rome_formatter::prelude::*;
use rome_formatter::{write, Format};
use rome_rowan::TextSize;
use rome_text_size::TextSize;

use crate::context::ASTFormatContext;
use crate::cst::Stmt;
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff_fmt/src/format/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use rome_formatter::prelude::*;
use rome_formatter::{format_args, write};
use rome_rowan::TextSize;
use rome_text_size::TextSize;
use rustpython_ast::Constant;

use crate::builders::literal;
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff_fmt/src/format/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use rome_formatter::prelude::*;
use rome_formatter::{format_args, write};
use rome_rowan::TextSize;
use rome_text_size::TextSize;

use crate::builders::literal;
use crate::context::ASTFormatContext;
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff_fmt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub fn fmt(contents: &str) -> Result<Printed> {
let python_ast = rustpython_helpers::parse_program_tokens(tokens, "<filename>")?;

// Convert to a CST.
let mut python_cst: Vec<Stmt> = python_ast.into_iter().map(Into::into).collect::<Vec<_>>();
let mut python_cst: Vec<Stmt> = python_ast.into_iter().map(Into::into).collect();

// Attach trivia.
attach(&mut python_cst, trivia);
Expand Down
30 changes: 0 additions & 30 deletions crates/ruff_fmt/src/shared_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,6 @@ where
}
}

/// Implement [`AsFormat`] for [`SyntaxResult`] where `T` implements
/// [`AsFormat`].
///
/// Useful to format mandatory AST fields without having to unwrap the value
/// first.
impl<T, C> AsFormat<C> for rome_rowan::SyntaxResult<T>
where
T: AsFormat<C>,
{
type Format<'a> = rome_rowan::SyntaxResult<T::Format<'a>> where Self: 'a;

fn format(&self) -> Self::Format<'_> {
match self {
Ok(value) => Ok(value.format()),
Err(err) => Err(*err),
}
}
}

/// Implement [`AsFormat`] for [`Option`] when `T` implements [`AsFormat`]
///
/// Allows to call format on optional AST fields without having to unwrap the
Expand All @@ -65,17 +46,6 @@ pub trait IntoFormat<Context> {
fn into_format(self) -> Self::Format;
}

impl<T, Context> IntoFormat<Context> for rome_rowan::SyntaxResult<T>
where
T: IntoFormat<Context>,
{
type Format = rome_rowan::SyntaxResult<T::Format>;

fn into_format(self) -> Self::Format {
self.map(IntoFormat::into_format)
}
}

/// Implement [`IntoFormat`] for [`Option`] when `T` implements [`IntoFormat`]
///
/// Allows to call format on optional AST fields without having to unwrap the
Expand Down

0 comments on commit 3c4fd73

Please sign in to comment.