1
Fork 0
mirror of https://github.com/RGBCube/alejandra synced 2025-07-30 12:07:46 +00:00

refactor: remove layout and config

This commit is contained in:
Kevin Amado 2022-02-23 12:28:48 -05:00
parent bafc3ac5a5
commit 55cb958dff
27 changed files with 440 additions and 741 deletions

View file

@ -35,24 +35,20 @@ pub fn parse(args: Vec<String>) -> clap::ArgMatches {
.get_matches_from(args)
}
pub fn stdin(config: alejandra_engine::config::Config) -> std::io::Result<()> {
pub fn stdin() -> std::io::Result<()> {
use std::io::Read;
eprintln!("Formatting stdin, run with --help to see all options.");
let mut stdin = String::new();
std::io::stdin().read_to_string(&mut stdin).unwrap();
let stdout =
alejandra_engine::format::string(&config, "stdin".to_string(), stdin)?;
let stdout = alejandra_engine::format::string("stdin".to_string(), stdin)?;
print!("{}", stdout);
Ok(())
}
pub fn simple(
config: alejandra_engine::config::Config,
paths: Vec<String>,
) -> std::io::Result<()> {
pub fn simple(paths: Vec<String>) -> std::io::Result<()> {
use rayon::prelude::*;
eprintln!("Formatting {} files.", paths.len());
@ -60,14 +56,12 @@ pub fn simple(
let (results, errors): (Vec<_>, Vec<_>) = paths
.par_iter()
.map(|path| -> std::io::Result<bool> {
alejandra_engine::format::file(&config, path.to_string()).map(
|changed| {
if changed {
eprintln!("Formatted: {}", &path);
}
changed
},
)
alejandra_engine::format::file(path.to_string()).map(|changed| {
if changed {
eprintln!("Formatted: {}", &path);
}
changed
})
})
.partition(Result::is_ok);
@ -80,10 +74,7 @@ pub fn simple(
Ok(())
}
pub fn tui(
config: alejandra_engine::config::Config,
paths: Vec<String>,
) -> std::io::Result<()> {
pub fn tui(paths: Vec<String>) -> std::io::Result<()> {
use rayon::prelude::*;
use termion::{input::TermRead, raw::IntoRawMode};
@ -137,7 +128,7 @@ pub fn tui(
let sender_finished = sender;
std::thread::spawn(move || {
paths.into_par_iter().for_each_with(sender_paths, |sender, path| {
let result = alejandra_engine::format::file(&config, path.clone());
let result = alejandra_engine::format::file(path.clone());
if let Err(error) = sender
.send(Event::FormattedPath(FormattedPath { path, result }))

View file

@ -5,7 +5,7 @@ pub fn nix_files(include: Vec<&str>, exclude: Vec<&str>) -> Vec<String> {
exclude.iter().flat_map(nix_files_in_path).collect();
let mut paths: Vec<String> =
include.difference(&exclude).map(|path| path.clone()).collect();
include.difference(&exclude).cloned().collect();
paths.sort();
paths

View file

@ -1,8 +1,6 @@
fn main() -> std::io::Result<()> {
let matches = alejandra_cli::cli::parse(std::env::args().collect());
let config = alejandra_engine::config::Config::default();
match matches.values_of("include") {
Some(include) => {
let include = include.collect();
@ -18,13 +16,13 @@ fn main() -> std::io::Result<()> {
&& atty::is(atty::Stream::Stdin)
&& atty::is(atty::Stream::Stdout)
{
alejandra_cli::cli::tui(config, paths)?;
alejandra_cli::cli::tui(paths)?;
} else {
alejandra_cli::cli::simple(config, paths)?;
alejandra_cli::cli::simple(paths)?;
}
}
None => {
alejandra_cli::cli::stdin(config)?;
alejandra_cli::cli::stdin()?;
}
}

View file

@ -13,39 +13,46 @@ pub enum Step {
#[derive(Clone)]
pub struct BuildCtx {
pub config: crate::config::Config,
pub force_wide: bool,
pub indentation: usize,
pub pos_new: crate::position::Position,
pub pos_old: crate::position::Position,
pub path: String,
pub vertical: bool,
}
impl BuildCtx {
pub fn new(
config: crate::config::Config,
force_wide: bool,
path: String,
pos_new: crate::position::Position,
pos_old: crate::position::Position,
vertical: bool,
) -> BuildCtx {
BuildCtx { config, force_wide, indentation: 0, path, pos_new, pos_old }
BuildCtx {
force_wide,
indentation: 0,
path,
pos_new,
pos_old,
vertical,
}
}
}
pub fn build(
config: &crate::config::Config,
element: rnix::SyntaxElement,
force_wide: bool,
path: String,
vertical: bool,
) -> Option<rowan::GreenNode> {
let mut builder = rowan::GreenNodeBuilder::new();
let mut build_ctx = BuildCtx::new(
config.clone(),
force_wide,
path,
crate::position::Position::default(),
crate::position::Position::default(),
vertical,
);
build_step(
@ -267,15 +274,10 @@ fn format_wider(
) {
match element {
rnix::SyntaxElement::Node(node) => {
let layout = if fits_in_single_line(build_ctx, node.clone().into())
{
crate::config::Layout::Wide
} else {
crate::config::Layout::Tall
};
let mut build_ctx_clone = build_ctx.clone();
build_ctx_clone.config = build_ctx.config.with_layout(layout);
build_ctx_clone.vertical =
!fits_in_single_line(build_ctx, node.clone().into());
format(builder, &mut build_ctx_clone, element);
}
rnix::SyntaxElement::Token(_) => {
@ -289,12 +291,7 @@ pub fn fits_in_single_line(
node: rnix::SyntaxElement,
) -> bool {
let line = build_ctx.pos_new.line;
let maybe_green_node = build(
&build_ctx.config.with_layout(crate::config::Layout::Wide),
node,
true,
build_ctx.path.clone(),
);
let maybe_green_node = build(node, true, build_ctx.path.clone(), false);
match maybe_green_node {
Some(_) => build_ctx.pos_new.line == line,

View file

@ -1,26 +0,0 @@
#[derive(Clone, Debug)]
pub enum Layout {
Tall,
Wide,
}
#[derive(Clone)]
pub struct Config {
layout: Layout,
}
impl Default for Config {
fn default() -> Config {
Config { layout: Layout::Tall }
}
}
impl Config {
pub fn layout(&self) -> &Layout {
&self.layout
}
pub fn with_layout(&self, layout: Layout) -> Config {
Config { layout }
}
}

View file

@ -1,8 +1,4 @@
pub fn string(
config: &crate::config::Config,
path: String,
string: String,
) -> std::io::Result<String> {
pub fn string(path: String, string: String) -> std::io::Result<String> {
let tokens = rnix::tokenizer::Tokenizer::new(&string);
let ast = rnix::parser::parse(tokens);
@ -15,33 +11,26 @@ pub fn string(
}
let green_node =
crate::builder::build(config, ast.node().into(), false, path).unwrap();
crate::builder::build(ast.node().into(), false, path, true).unwrap();
Ok(green_node.to_string())
}
pub fn string_or_passthrough(
config: &crate::config::Config,
path: String,
before: String,
) -> String {
match crate::format::string(config, path, before.clone()) {
pub fn string_or_passthrough(path: String, before: String) -> String {
match crate::format::string(path, before.clone()) {
Ok(after) => after,
Err(_) => before,
}
}
pub fn file(
config: &crate::config::Config,
path: String,
) -> std::io::Result<bool> {
pub fn file(path: String) -> std::io::Result<bool> {
use std::io::Write;
let input = std::fs::read_to_string(&path)?;
let input_clone = input.clone();
let input_bytes = input_clone.as_bytes();
let output = crate::format::string(config, path.clone(), input)?;
let output = crate::format::string(path.clone(), input)?;
let output_bytes = output.as_bytes();
let changed = input_bytes != output_bytes;

View file

@ -1,6 +1,5 @@
pub mod builder;
pub mod children;
pub mod config;
pub mod format;
pub mod parsers;
pub mod position;

View file

@ -1,23 +1,13 @@
use std::collections::LinkedList;
#[derive(Debug)]
#[derive(Debug, Default)]
pub struct Argument {
pub comments_before: LinkedList<String>,
pub item: Option<rnix::SyntaxElement>,
pub comment_after: Option<String>,
}
impl Default for Argument {
fn default() -> Argument {
Argument {
comments_before: LinkedList::new(),
item: None,
comment_after: None,
}
}
}
#[derive(Debug)]
#[derive(Debug, Default)]
pub struct Pattern {
pub initial_at: Option<rnix::SyntaxElement>,
pub comments_after_initial_at: LinkedList<String>,
@ -27,19 +17,6 @@ pub struct Pattern {
pub end_at: Option<rnix::SyntaxElement>,
}
impl Default for Pattern {
fn default() -> Pattern {
Pattern {
initial_at: None,
comments_after_initial_at: LinkedList::new(),
arguments: LinkedList::new(),
comments_before_curly_b_close: LinkedList::new(),
comments_before_end_at: LinkedList::new(),
end_at: None,
}
}
}
pub fn parse(
build_ctx: &crate::builder::BuildCtx,
node: &rnix::SyntaxNode,

View file

@ -8,21 +8,17 @@ pub fn rule(
build_ctx, node, true,
);
let layout = if children.has_comments() || children.has_newlines() {
&crate::config::Layout::Tall
} else {
build_ctx.config.layout()
};
let vertical = children.has_comments()
|| children.has_newlines()
|| build_ctx.vertical;
// left
let child = children.get_next().unwrap();
match layout {
crate::config::Layout::Tall => {
steps.push_back(crate::builder::Step::FormatWider(child.element));
}
crate::config::Layout::Wide => {
steps.push_back(crate::builder::Step::Format(child.element));
}
if vertical {
steps.push_back(crate::builder::Step::FormatWider(child.element));
} else {
steps.push_back(crate::builder::Step::Format(child.element));
}
// /**/
@ -39,29 +35,26 @@ pub fn rule(
// right
let child = children.get_next().unwrap();
match layout {
crate::config::Layout::Tall => {
if let rnix::SyntaxKind::TOKEN_COMMENT
| rnix::SyntaxKind::TOKEN_WHITESPACE = child_prev.element.kind()
{
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
} else if let rnix::SyntaxKind::NODE_ATTR_SET
| rnix::SyntaxKind::NODE_LIST
| rnix::SyntaxKind::NODE_PAREN
| rnix::SyntaxKind::NODE_STRING = child.element.kind()
{
steps.push_back(crate::builder::Step::Whitespace);
} else {
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
};
steps.push_back(crate::builder::Step::FormatWider(child.element));
}
crate::config::Layout::Wide => {
if vertical {
if let rnix::SyntaxKind::TOKEN_COMMENT
| rnix::SyntaxKind::TOKEN_WHITESPACE = child_prev.element.kind()
{
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
} else if let rnix::SyntaxKind::NODE_ATTR_SET
| rnix::SyntaxKind::NODE_LIST
| rnix::SyntaxKind::NODE_PAREN
| rnix::SyntaxKind::NODE_STRING = child.element.kind()
{
steps.push_back(crate::builder::Step::Whitespace);
steps.push_back(crate::builder::Step::Format(child.element));
}
} else {
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
};
steps.push_back(crate::builder::Step::FormatWider(child.element));
} else {
steps.push_back(crate::builder::Step::Whitespace);
steps.push_back(crate::builder::Step::Format(child.element));
}
steps

View file

@ -8,11 +8,9 @@ pub fn rule(
build_ctx, node, true,
);
let layout = if children.has_comments() || children.has_newlines() {
&crate::config::Layout::Tall
} else {
build_ctx.config.layout()
};
let vertical = children.has_comments()
|| children.has_newlines()
|| build_ctx.vertical;
// with
let child = children.get_next().unwrap();
@ -39,13 +37,10 @@ pub fn rule(
// expr
let child = children.get_next().unwrap();
match layout {
crate::config::Layout::Tall => {
steps.push_back(crate::builder::Step::FormatWider(child.element));
}
crate::config::Layout::Wide => {
steps.push_back(crate::builder::Step::Format(child.element));
}
if vertical {
steps.push_back(crate::builder::Step::FormatWider(child.element));
} else {
steps.push_back(crate::builder::Step::Format(child.element));
}
// ;
@ -66,49 +61,40 @@ pub fn rule(
// expr
let child = children.get_next().unwrap();
match layout {
crate::config::Layout::Tall => {
if {
matches!(
child.element.kind(),
rnix::SyntaxKind::NODE_ASSERT | rnix::SyntaxKind::NODE_WITH
)
} {
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
steps.push_back(crate::builder::Step::FormatWider(
child.element,
));
} else if comment
|| !matches!(
child.element.kind(),
rnix::SyntaxKind::NODE_ATTR_SET
| rnix::SyntaxKind::NODE_IDENT
| rnix::SyntaxKind::NODE_PAREN
| rnix::SyntaxKind::NODE_LET_IN
| rnix::SyntaxKind::NODE_LIST
| rnix::SyntaxKind::NODE_LITERAL
| rnix::SyntaxKind::NODE_STRING
)
{
steps.push_back(crate::builder::Step::Indent);
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
steps.push_back(crate::builder::Step::FormatWider(
child.element,
));
steps.push_back(crate::builder::Step::Dedent);
} else {
steps.push_back(crate::builder::Step::Whitespace);
steps.push_back(crate::builder::Step::FormatWider(
child.element,
));
}
}
crate::config::Layout::Wide => {
if vertical {
if {
matches!(
child.element.kind(),
rnix::SyntaxKind::NODE_ASSERT | rnix::SyntaxKind::NODE_WITH
)
} {
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
steps.push_back(crate::builder::Step::FormatWider(child.element));
} else if comment
|| !matches!(
child.element.kind(),
rnix::SyntaxKind::NODE_ATTR_SET
| rnix::SyntaxKind::NODE_IDENT
| rnix::SyntaxKind::NODE_PAREN
| rnix::SyntaxKind::NODE_LET_IN
| rnix::SyntaxKind::NODE_LIST
| rnix::SyntaxKind::NODE_LITERAL
| rnix::SyntaxKind::NODE_STRING
)
{
steps.push_back(crate::builder::Step::Indent);
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
steps.push_back(crate::builder::Step::FormatWider(child.element));
steps.push_back(crate::builder::Step::Dedent);
} else {
steps.push_back(crate::builder::Step::Whitespace);
steps.push_back(crate::builder::Step::Format(child.element));
steps.push_back(crate::builder::Step::FormatWider(child.element));
}
} else {
steps.push_back(crate::builder::Step::Whitespace);
steps.push_back(crate::builder::Step::Format(child.element));
}
steps

View file

@ -27,14 +27,10 @@ pub fn rule(
})
.count();
let layout = if items_count > 1
let vertical = items_count > 1
|| children.has_comments()
|| children.has_newlines()
{
&crate::config::Layout::Tall
} else {
build_ctx.config.layout()
};
|| build_ctx.vertical;
// rec
let child = children.peek_next().unwrap();
@ -66,11 +62,8 @@ pub fn rule(
// {
let child = children.get_next().unwrap();
steps.push_back(crate::builder::Step::Format(child.element));
match layout {
crate::config::Layout::Tall => {
steps.push_back(crate::builder::Step::Indent);
}
crate::config::Layout::Wide => {}
if vertical {
steps.push_back(crate::builder::Step::Indent);
}
let mut item_index: usize = 0;
@ -107,23 +100,18 @@ pub fn rule(
// item
item_index += 1;
match layout {
crate::config::Layout::Tall => {
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
steps.push_back(crate::builder::Step::FormatWider(
child.element,
));
}
crate::config::Layout::Wide => {
if item_index > 1 {
steps.push_back(crate::builder::Step::Whitespace);
}
steps
.push_back(crate::builder::Step::Format(child.element));
if vertical {
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
steps.push_back(crate::builder::Step::FormatWider(
child.element,
));
} else {
if item_index > 1 {
steps.push_back(crate::builder::Step::Whitespace);
}
steps.push_back(crate::builder::Step::Format(child.element));
}
children.move_next();
inline_next_comment = true;
}
@ -131,13 +119,10 @@ pub fn rule(
// }
let child = children.get_next().unwrap();
match layout {
crate::config::Layout::Tall => {
steps.push_back(crate::builder::Step::Dedent);
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
}
crate::config::Layout::Wide => {}
if vertical {
steps.push_back(crate::builder::Step::Dedent);
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
}
steps.push_back(crate::builder::Step::Format(child.element));

View file

@ -16,39 +16,32 @@ pub fn rule_with_configuration(
build_ctx, node, true,
);
let layout = if children.has_comments() || children.has_newlines() {
&crate::config::Layout::Tall
} else {
build_ctx.config.layout()
};
let vertical = children.has_comments()
|| children.has_newlines()
|| build_ctx.vertical;
// expr
let child = children.get_next().unwrap();
match layout {
crate::config::Layout::Tall => {
let kind = child.element.kind();
if vertical {
let kind = child.element.kind();
if (parent_kind == "bin_op_and_or_default"
&& matches!(
kind,
rnix::SyntaxKind::NODE_BIN_OP
| rnix::SyntaxKind::NODE_OR_DEFAULT
))
|| (parent_kind == "select"
&& matches!(kind, rnix::SyntaxKind::NODE_SELECT))
{
steps.push_back(crate::builder::Step::Format(child.element));
} else {
steps.push_back(crate::builder::Step::FormatWider(
child.element,
));
}
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
}
crate::config::Layout::Wide => {
if (parent_kind == "bin_op_and_or_default"
&& matches!(
kind,
rnix::SyntaxKind::NODE_BIN_OP
| rnix::SyntaxKind::NODE_OR_DEFAULT
))
|| (parent_kind == "select"
&& matches!(kind, rnix::SyntaxKind::NODE_SELECT))
{
steps.push_back(crate::builder::Step::Format(child.element));
} else {
steps.push_back(crate::builder::Step::FormatWider(child.element));
}
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
} else {
steps.push_back(crate::builder::Step::Format(child.element));
}
// /**/
@ -63,13 +56,9 @@ pub fn rule_with_configuration(
// operator
let child = children.get_next().unwrap();
match layout {
crate::config::Layout::Tall => {}
crate::config::Layout::Wide => {
if parent_kind == "bin_op_and_or_default" {
steps.push_back(crate::builder::Step::Whitespace);
}
}
if vertical {
} else if parent_kind == "bin_op_and_or_default" {
steps.push_back(crate::builder::Step::Whitespace);
}
steps.push_back(crate::builder::Step::Format(child.element));
@ -94,13 +83,10 @@ pub fn rule_with_configuration(
// expr
let child = children.get_next().unwrap();
match layout {
crate::config::Layout::Tall => {
steps.push_back(crate::builder::Step::FormatWider(child.element));
}
crate::config::Layout::Wide => {
steps.push_back(crate::builder::Step::Format(child.element));
}
if vertical {
steps.push_back(crate::builder::Step::FormatWider(child.element));
} else {
steps.push_back(crate::builder::Step::Format(child.element));
}
steps

View file

@ -8,22 +8,17 @@ pub fn rule(
build_ctx, node, true,
);
let layout = if children.has_comments() || children.has_newlines() {
&crate::config::Layout::Tall
} else {
build_ctx.config.layout()
};
let vertical = children.has_comments()
|| children.has_newlines()
|| build_ctx.vertical;
// ${
let child = children.get_next().unwrap();
steps.push_back(crate::builder::Step::Format(child.element));
match layout {
crate::config::Layout::Tall => {
steps.push_back(crate::builder::Step::Indent);
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
}
crate::config::Layout::Wide => {}
if vertical {
steps.push_back(crate::builder::Step::Indent);
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
}
// /**/
@ -38,13 +33,10 @@ pub fn rule(
// expr
let child = children.get_next().unwrap();
match layout {
crate::config::Layout::Tall => {
steps.push_back(crate::builder::Step::FormatWider(child.element));
}
crate::config::Layout::Wide => {
steps.push_back(crate::builder::Step::Format(child.element));
}
if vertical {
steps.push_back(crate::builder::Step::FormatWider(child.element));
} else {
steps.push_back(crate::builder::Step::Format(child.element));
}
// /**/
@ -59,13 +51,10 @@ pub fn rule(
// }
let child = children.get_next().unwrap();
match layout {
crate::config::Layout::Tall => {
steps.push_back(crate::builder::Step::Dedent);
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
}
crate::config::Layout::Wide => {}
if vertical {
steps.push_back(crate::builder::Step::Dedent);
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
}
steps.push_back(crate::builder::Step::Format(child.element));

View file

@ -8,20 +8,15 @@ pub fn rule(
build_ctx, node, true,
);
let layout = if children.has_comments() || children.has_newlines() {
&crate::config::Layout::Tall
} else {
build_ctx.config.layout()
};
let vertical = children.has_comments()
|| children.has_newlines()
|| build_ctx.vertical;
// inherit
let child = children.get_next().unwrap();
steps.push_back(crate::builder::Step::Format(child.element));
match layout {
crate::config::Layout::Tall => {
steps.push_back(crate::builder::Step::Indent);
}
crate::config::Layout::Wide => {}
if vertical {
steps.push_back(crate::builder::Step::Indent);
}
loop {
@ -37,35 +32,27 @@ pub fn rule(
if let Some(child) = children.get_next() {
// expr
match layout {
crate::config::Layout::Tall => {
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
steps.push_back(crate::builder::Step::FormatWider(
child.element,
));
}
crate::config::Layout::Wide => {
if let rnix::SyntaxKind::TOKEN_SEMICOLON =
child.element.kind()
{
} else {
steps.push_back(crate::builder::Step::Whitespace);
}
steps
.push_back(crate::builder::Step::Format(child.element));
if vertical {
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
steps.push_back(crate::builder::Step::FormatWider(
child.element,
));
} else {
if let rnix::SyntaxKind::TOKEN_SEMICOLON = child.element.kind()
{
} else {
steps.push_back(crate::builder::Step::Whitespace);
}
steps.push_back(crate::builder::Step::Format(child.element));
}
} else {
break;
}
}
match layout {
crate::config::Layout::Tall => {
steps.push_back(crate::builder::Step::Dedent);
}
crate::config::Layout::Wide => {}
if vertical {
steps.push_back(crate::builder::Step::Dedent);
}
steps

View file

@ -8,21 +8,16 @@ pub fn rule(
build_ctx, node, true,
);
let layout = if children.has_comments() || children.has_newlines() {
&crate::config::Layout::Tall
} else {
build_ctx.config.layout()
};
let vertical = children.has_comments()
|| children.has_newlines()
|| build_ctx.vertical;
// a
let child = children.get_next().unwrap();
match layout {
crate::config::Layout::Tall => {
steps.push_back(crate::builder::Step::FormatWider(child.element));
}
crate::config::Layout::Wide => {
steps.push_back(crate::builder::Step::Format(child.element));
}
if vertical {
steps.push_back(crate::builder::Step::FormatWider(child.element));
} else {
steps.push_back(crate::builder::Step::Format(child.element));
}
// /**/
@ -76,39 +71,36 @@ pub fn rule(
let mut dedent = false;
steps.push_back(crate::builder::Step::Format(child_equal.element));
match layout {
crate::config::Layout::Tall => {
if !comments_before.is_empty() || !comments_after.is_empty() {
dedent = true;
steps.push_back(crate::builder::Step::Indent);
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
} else if matches!(
child_expr.element.kind(),
rnix::SyntaxKind::NODE_ASSERT
| rnix::SyntaxKind::NODE_ATTR_SET
| rnix::SyntaxKind::NODE_PAREN
| rnix::SyntaxKind::NODE_LAMBDA
| rnix::SyntaxKind::NODE_LET_IN
| rnix::SyntaxKind::NODE_LIST
| rnix::SyntaxKind::NODE_STRING
| rnix::SyntaxKind::NODE_WITH
) || (matches!(
child_expr.element.kind(),
rnix::SyntaxKind::NODE_APPLY
) && !newlines)
{
steps.push_back(crate::builder::Step::Whitespace);
} else {
dedent = true;
steps.push_back(crate::builder::Step::Indent);
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
}
}
crate::config::Layout::Wide => {
if vertical {
if !comments_before.is_empty() || !comments_after.is_empty() {
dedent = true;
steps.push_back(crate::builder::Step::Indent);
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
} else if matches!(
child_expr.element.kind(),
rnix::SyntaxKind::NODE_ASSERT
| rnix::SyntaxKind::NODE_ATTR_SET
| rnix::SyntaxKind::NODE_PAREN
| rnix::SyntaxKind::NODE_LAMBDA
| rnix::SyntaxKind::NODE_LET_IN
| rnix::SyntaxKind::NODE_LIST
| rnix::SyntaxKind::NODE_STRING
| rnix::SyntaxKind::NODE_WITH
) || (matches!(
child_expr.element.kind(),
rnix::SyntaxKind::NODE_APPLY
) && !newlines)
{
steps.push_back(crate::builder::Step::Whitespace);
} else {
dedent = true;
steps.push_back(crate::builder::Step::Indent);
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
}
} else {
steps.push_back(crate::builder::Step::Whitespace);
}
// /**/
@ -119,19 +111,14 @@ pub fn rule(
}
// expr
match layout {
crate::config::Layout::Tall => {
steps.push_back(crate::builder::Step::FormatWider(
child_expr.element,
));
if !comments_after.is_empty() {
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
}
}
crate::config::Layout::Wide => {
steps.push_back(crate::builder::Step::Format(child_expr.element));
if vertical {
steps.push_back(crate::builder::Step::FormatWider(child_expr.element));
if !comments_after.is_empty() {
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
}
} else {
steps.push_back(crate::builder::Step::Format(child_expr.element));
}
// /**/

View file

@ -8,21 +8,16 @@ pub fn rule(
build_ctx, node, true,
);
let layout = if children.has_comments() || children.has_newlines() {
&crate::config::Layout::Tall
} else {
build_ctx.config.layout()
};
let vertical = children.has_comments()
|| children.has_newlines()
|| build_ctx.vertical;
// a
let child = children.get_next().unwrap();
match layout {
crate::config::Layout::Tall => {
steps.push_back(crate::builder::Step::FormatWider(child.element));
}
crate::config::Layout::Wide => {
steps.push_back(crate::builder::Step::Format(child.element));
}
if vertical {
steps.push_back(crate::builder::Step::FormatWider(child.element));
} else {
steps.push_back(crate::builder::Step::Format(child.element));
}
if let rnix::SyntaxKind::TOKEN_COMMENT
@ -61,53 +56,46 @@ pub fn rule(
// c
let child = children.get_next().unwrap();
match layout {
crate::config::Layout::Tall => {
if comment
|| !matches!(
child.element.kind(),
rnix::SyntaxKind::NODE_ATTR_SET
| rnix::SyntaxKind::NODE_PAREN
| rnix::SyntaxKind::NODE_LAMBDA
| rnix::SyntaxKind::NODE_LET_IN
| rnix::SyntaxKind::NODE_LIST
| rnix::SyntaxKind::NODE_LITERAL
| rnix::SyntaxKind::NODE_STRING
)
{
let should_indent = !matches!(
child.element.kind(),
rnix::SyntaxKind::NODE_ATTR_SET
| rnix::SyntaxKind::NODE_PAREN
| rnix::SyntaxKind::NODE_LAMBDA
| rnix::SyntaxKind::NODE_LET_IN
| rnix::SyntaxKind::NODE_LIST
| rnix::SyntaxKind::NODE_STRING
) && build_ctx.pos_new.column > 1;
if vertical {
if comment
|| !matches!(
child.element.kind(),
rnix::SyntaxKind::NODE_ATTR_SET
| rnix::SyntaxKind::NODE_PAREN
| rnix::SyntaxKind::NODE_LAMBDA
| rnix::SyntaxKind::NODE_LET_IN
| rnix::SyntaxKind::NODE_LIST
| rnix::SyntaxKind::NODE_LITERAL
| rnix::SyntaxKind::NODE_STRING
)
{
let should_indent = !matches!(
child.element.kind(),
rnix::SyntaxKind::NODE_ATTR_SET
| rnix::SyntaxKind::NODE_PAREN
| rnix::SyntaxKind::NODE_LAMBDA
| rnix::SyntaxKind::NODE_LET_IN
| rnix::SyntaxKind::NODE_LIST
| rnix::SyntaxKind::NODE_STRING
) && build_ctx.pos_new.column > 1;
if should_indent {
steps.push_back(crate::builder::Step::Indent);
}
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
steps.push_back(crate::builder::Step::FormatWider(
child.element,
));
if should_indent {
steps.push_back(crate::builder::Step::Dedent);
}
} else {
steps.push_back(crate::builder::Step::Whitespace);
steps.push_back(crate::builder::Step::FormatWider(
child.element,
));
if should_indent {
steps.push_back(crate::builder::Step::Indent);
}
}
crate::config::Layout::Wide => {
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
steps.push_back(crate::builder::Step::FormatWider(child.element));
if should_indent {
steps.push_back(crate::builder::Step::Dedent);
}
} else {
steps.push_back(crate::builder::Step::Whitespace);
steps.push_back(crate::builder::Step::Format(child.element));
steps.push_back(crate::builder::Step::FormatWider(child.element));
}
} else {
steps.push_back(crate::builder::Step::Whitespace);
steps.push_back(crate::builder::Step::Format(child.element));
}
steps

View file

@ -20,23 +20,16 @@ pub fn rule(
})
.count();
let layout = if items_count > 1
let vertical = items_count > 1
|| children.has_comments()
|| children.has_newlines()
{
&crate::config::Layout::Tall
} else {
build_ctx.config.layout()
};
|| build_ctx.vertical;
// let
let child = children.get_next().unwrap();
steps.push_back(crate::builder::Step::Format(child.element));
match layout {
crate::config::Layout::Tall => {
steps.push_back(crate::builder::Step::Indent);
}
crate::config::Layout::Wide => {}
if vertical {
steps.push_back(crate::builder::Step::Indent);
}
let mut item_index: usize = 0;
@ -71,19 +64,15 @@ pub fn rule(
// expr
item_index += 1;
match layout {
crate::config::Layout::Tall => {
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
steps.push_back(crate::builder::Step::FormatWider(
child.element,
));
}
crate::config::Layout::Wide => {
steps.push_back(crate::builder::Step::Whitespace);
steps
.push_back(crate::builder::Step::Format(child.element));
}
if vertical {
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
steps.push_back(crate::builder::Step::FormatWider(
child.element,
));
} else {
steps.push_back(crate::builder::Step::Whitespace);
steps.push_back(crate::builder::Step::Format(child.element));
}
children.move_next();
@ -91,15 +80,12 @@ pub fn rule(
}
}
match layout {
crate::config::Layout::Tall => {
steps.push_back(crate::builder::Step::Dedent);
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
}
crate::config::Layout::Wide => {
steps.push_back(crate::builder::Step::Whitespace);
}
if vertical {
steps.push_back(crate::builder::Step::Dedent);
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
} else {
steps.push_back(crate::builder::Step::Whitespace);
}
// in
@ -120,27 +106,24 @@ pub fn rule(
// in
let mut dedent = false;
steps.push_back(crate::builder::Step::Format(child_in.element));
match layout {
crate::config::Layout::Tall => {
if child_comments.is_empty()
&& matches!(
child_expr.element.kind(),
rnix::SyntaxKind::NODE_ATTR_SET
| rnix::SyntaxKind::NODE_LET_IN
| rnix::SyntaxKind::NODE_LIST
| rnix::SyntaxKind::NODE_PAREN
| rnix::SyntaxKind::NODE_STRING
)
{
steps.push_back(crate::builder::Step::Whitespace);
} else {
dedent = true;
steps.push_back(crate::builder::Step::Indent);
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
}
if vertical {
if child_comments.is_empty()
&& matches!(
child_expr.element.kind(),
rnix::SyntaxKind::NODE_ATTR_SET
| rnix::SyntaxKind::NODE_LET_IN
| rnix::SyntaxKind::NODE_LIST
| rnix::SyntaxKind::NODE_PAREN
| rnix::SyntaxKind::NODE_STRING
)
{
steps.push_back(crate::builder::Step::Whitespace);
} else {
dedent = true;
steps.push_back(crate::builder::Step::Indent);
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
}
crate::config::Layout::Wide => {}
}
// /**/
@ -151,19 +134,14 @@ pub fn rule(
}
// expr
match layout {
crate::config::Layout::Tall => {
steps.push_back(crate::builder::Step::FormatWider(
child_expr.element,
));
if dedent {
steps.push_back(crate::builder::Step::Dedent);
}
}
crate::config::Layout::Wide => {
steps.push_back(crate::builder::Step::Whitespace);
steps.push_back(crate::builder::Step::Format(child_expr.element));
if vertical {
steps.push_back(crate::builder::Step::FormatWider(child_expr.element));
if dedent {
steps.push_back(crate::builder::Step::Dedent);
}
} else {
steps.push_back(crate::builder::Step::Whitespace);
steps.push_back(crate::builder::Step::Format(child_expr.element));
}
steps

View file

@ -16,20 +16,15 @@ pub fn rule(
.count()
- 2;
let layout = if children.has_comments() || children.has_newlines() {
&crate::config::Layout::Tall
} else {
build_ctx.config.layout()
};
let vertical = children.has_comments()
|| children.has_newlines()
|| build_ctx.vertical;
// [
let child = children.get_next().unwrap();
steps.push_back(crate::builder::Step::Format(child.element));
match layout {
crate::config::Layout::Tall => {
steps.push_back(crate::builder::Step::Indent);
}
crate::config::Layout::Wide => {}
if vertical {
steps.push_back(crate::builder::Step::Indent);
}
let mut item_index: usize = 0;
@ -73,21 +68,17 @@ pub fn rule(
// item
item_index += 1;
match layout {
crate::config::Layout::Tall => {
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
steps.push_back(crate::builder::Step::FormatWider(
child.element,
));
}
crate::config::Layout::Wide => {
if item_index > 1 {
steps.push_back(crate::builder::Step::Whitespace);
}
steps
.push_back(crate::builder::Step::Format(child.element));
if vertical {
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
steps.push_back(crate::builder::Step::FormatWider(
child.element,
));
} else {
if item_index > 1 {
steps.push_back(crate::builder::Step::Whitespace);
}
steps.push_back(crate::builder::Step::Format(child.element));
}
children.move_next();
@ -97,13 +88,10 @@ pub fn rule(
// ]
let child = children.get_next().unwrap();
match layout {
crate::config::Layout::Tall => {
steps.push_back(crate::builder::Step::Dedent);
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
}
crate::config::Layout::Wide => {}
if vertical {
steps.push_back(crate::builder::Step::Dedent);
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
}
steps.push_back(crate::builder::Step::Format(child.element));

View file

@ -27,10 +27,8 @@ pub fn default(
let mut children = crate::children::Children::new(build_ctx, node);
while let Some(child) = children.get_next() {
let step = match build_ctx.config.layout() {
crate::config::Layout::Tall => {
crate::builder::Step::FormatWider(child.element)
}
let step = match build_ctx.vertical {
true => crate::builder::Step::FormatWider(child.element),
_ => crate::builder::Step::Format(child.element),
};
steps.push_back(step);

View file

@ -11,22 +11,13 @@ pub fn rule(
let has_comments_or_newlines =
children.has_comments() || children.has_newlines();
let layout = if has_comments_or_newlines {
&crate::config::Layout::Tall
} else {
build_ctx.config.layout()
};
let vertical = has_comments_or_newlines || build_ctx.vertical;
// (
let child = children.get_next().unwrap();
steps.push_back(crate::builder::Step::Format(child.element));
match layout {
crate::config::Layout::Tall => {
if has_comments_or_newlines {
steps.push_back(crate::builder::Step::Indent);
}
}
crate::config::Layout::Wide => {}
if vertical && has_comments_or_newlines {
steps.push_back(crate::builder::Step::Indent);
}
// /**/
@ -41,17 +32,14 @@ pub fn rule(
// expr
let child = children.get_next().unwrap();
match layout {
crate::config::Layout::Tall => {
if has_comments_or_newlines {
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
}
steps.push_back(crate::builder::Step::FormatWider(child.element));
}
crate::config::Layout::Wide => {
steps.push_back(crate::builder::Step::Format(child.element));
if vertical {
if has_comments_or_newlines {
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
}
steps.push_back(crate::builder::Step::FormatWider(child.element));
} else {
steps.push_back(crate::builder::Step::Format(child.element));
}
// /**/
@ -66,15 +54,10 @@ pub fn rule(
// )
let child = children.get_next().unwrap();
match layout {
crate::config::Layout::Tall => {
if has_comments_or_newlines {
steps.push_back(crate::builder::Step::Dedent);
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
}
}
crate::config::Layout::Wide => {}
if vertical && has_comments_or_newlines {
steps.push_back(crate::builder::Step::Dedent);
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
}
steps.push_back(crate::builder::Step::Format(child.element));

View file

@ -8,20 +8,15 @@ pub fn rule(
build_ctx, node, true,
);
let layout = if children.has_comments() || children.has_newlines() {
&crate::config::Layout::Tall
} else {
build_ctx.config.layout()
};
let vertical = children.has_comments()
|| children.has_newlines()
|| build_ctx.vertical;
let child = children.get_next().unwrap();
match layout {
crate::config::Layout::Tall => {
steps.push_back(crate::builder::Step::FormatWider(child.element));
}
crate::config::Layout::Wide => {
steps.push_back(crate::builder::Step::Format(child.element));
}
if vertical {
steps.push_back(crate::builder::Step::FormatWider(child.element));
} else {
steps.push_back(crate::builder::Step::Format(child.element));
}
// /**/
@ -44,13 +39,10 @@ pub fn rule(
}
let child = children.get_next().unwrap();
match layout {
crate::config::Layout::Tall => {
steps.push_back(crate::builder::Step::FormatWider(child.element));
}
crate::config::Layout::Wide => {
steps.push_back(crate::builder::Step::Format(child.element));
}
if vertical {
steps.push_back(crate::builder::Step::FormatWider(child.element));
} else {
steps.push_back(crate::builder::Step::Format(child.element));
}
children.move_prev();

View file

@ -8,21 +8,16 @@ pub fn rule(
build_ctx, node, true,
);
let layout = if children.has_comments() || children.has_newlines() {
&crate::config::Layout::Tall
} else {
build_ctx.config.layout()
};
let vertical = children.has_comments()
|| children.has_newlines()
|| build_ctx.vertical;
// expr
let child = children.get_next().unwrap();
match layout {
crate::config::Layout::Tall => {
steps.push_back(crate::builder::Step::FormatWider(child.element));
}
crate::config::Layout::Wide => {
steps.push_back(crate::builder::Step::Format(child.element));
}
if vertical {
steps.push_back(crate::builder::Step::FormatWider(child.element));
} else {
steps.push_back(crate::builder::Step::Format(child.element));
}
if children.has_next() {
@ -90,15 +85,10 @@ pub fn rule(
steps.push_back(crate::builder::Step::Pad);
}
match layout {
crate::config::Layout::Tall => {
steps.push_back(crate::builder::Step::FormatWider(
child.element,
));
}
crate::config::Layout::Wide => {
steps.push_back(crate::builder::Step::Format(child.element));
}
if vertical {
steps.push_back(crate::builder::Step::FormatWider(child.element));
} else {
steps.push_back(crate::builder::Step::Format(child.element));
}
if dedent {
steps.push_back(crate::builder::Step::Dedent);

View file

@ -29,25 +29,18 @@ pub fn rule(
let arguments_count_for_tall = if has_ellipsis { 2 } else { 1 };
let layout = if has_comments
let vertical = has_comments
|| arguments_count > arguments_count_for_tall
|| (arguments_count > 0 && has_comments_between_curly_b)
{
&crate::config::Layout::Tall
} else {
build_ctx.config.layout()
};
|| build_ctx.vertical;
// x @
if let Some(element) = &pattern.initial_at {
let element = element.clone();
match layout {
crate::config::Layout::Tall => {
steps.push_back(crate::builder::Step::FormatWider(element));
}
crate::config::Layout::Wide => {
steps.push_back(crate::builder::Step::Format(element));
}
if vertical {
steps.push_back(crate::builder::Step::FormatWider(element));
} else {
steps.push_back(crate::builder::Step::Format(element));
}
}
@ -69,26 +62,17 @@ pub fn rule(
rnix::SyntaxKind::TOKEN_CURLY_B_OPEN,
"{".to_string(),
));
match layout {
crate::config::Layout::Tall => {
steps.push_back(crate::builder::Step::Indent);
}
crate::config::Layout::Wide => {}
};
if vertical {
steps.push_back(crate::builder::Step::Indent);
}
// arguments
let mut index = 0;
for argument in pattern.arguments {
match layout {
crate::config::Layout::Tall => {
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
}
crate::config::Layout::Wide => {
if index > 0 {
steps.push_back(crate::builder::Step::Whitespace);
}
}
for (index, argument) in pattern.arguments.into_iter().enumerate() {
if vertical {
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
} else if index > 0 {
steps.push_back(crate::builder::Step::Whitespace);
}
// /**/
@ -103,33 +87,25 @@ pub fn rule(
// argument
let element = argument.item.unwrap();
let element_kind = element.kind();
match layout {
crate::config::Layout::Tall => {
steps.push_back(crate::builder::Step::FormatWider(element));
}
crate::config::Layout::Wide => {
steps.push_back(crate::builder::Step::Format(element));
}
if vertical {
steps.push_back(crate::builder::Step::FormatWider(element));
} else {
steps.push_back(crate::builder::Step::Format(element));
};
// ,
match layout {
crate::config::Layout::Tall => {
if !matches!(element_kind, rnix::SyntaxKind::TOKEN_ELLIPSIS) {
steps.push_back(crate::builder::Step::Token(
rnix::SyntaxKind::TOKEN_COMMA,
",".to_string(),
));
}
}
crate::config::Layout::Wide => {
if index + 1 < arguments_count {
steps.push_back(crate::builder::Step::Token(
rnix::SyntaxKind::TOKEN_COMMA,
",".to_string(),
));
}
if vertical {
if !matches!(element_kind, rnix::SyntaxKind::TOKEN_ELLIPSIS) {
steps.push_back(crate::builder::Step::Token(
rnix::SyntaxKind::TOKEN_COMMA,
",".to_string(),
));
}
} else if index + 1 < arguments_count {
steps.push_back(crate::builder::Step::Token(
rnix::SyntaxKind::TOKEN_COMMA,
",".to_string(),
));
};
// possible inline comment
@ -142,8 +118,6 @@ pub fn rule(
}
steps.push_back(crate::builder::Step::Comment(text));
}
index += 1;
}
// /**/
@ -156,16 +130,13 @@ pub fn rule(
}
// }
match layout {
crate::config::Layout::Tall => {
steps.push_back(crate::builder::Step::Dedent);
if arguments_count > 0 || has_comments_before_curly_b_close {
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
}
if vertical {
steps.push_back(crate::builder::Step::Dedent);
if arguments_count > 0 || has_comments_before_curly_b_close {
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
}
crate::config::Layout::Wide => {}
};
}
steps.push_back(crate::builder::Step::Token(
rnix::SyntaxKind::TOKEN_CURLY_B_OPEN,
"}".to_string(),
@ -188,13 +159,10 @@ pub fn rule(
// @ x
if let Some(element) = pattern.end_at {
match layout {
crate::config::Layout::Tall => {
steps.push_back(crate::builder::Step::FormatWider(element));
}
crate::config::Layout::Wide => {
steps.push_back(crate::builder::Step::Format(element));
}
if vertical {
steps.push_back(crate::builder::Step::FormatWider(element));
} else {
steps.push_back(crate::builder::Step::Format(element));
}
}

View file

@ -8,11 +8,9 @@ pub fn rule(
build_ctx, node, true,
);
let layout = if children.has_comments() || children.has_newlines() {
&crate::config::Layout::Tall
} else {
build_ctx.config.layout()
};
let vertical = children.has_comments()
|| children.has_newlines()
|| build_ctx.vertical;
while children.has_next() {
children.drain_comments_and_newlines(|element| match element {
@ -25,17 +23,13 @@ pub fn rule(
});
if let Some(child) = children.get_next() {
match layout {
crate::config::Layout::Tall => {
steps.push_back(crate::builder::Step::FormatWider(
child.element,
));
steps.push_back(crate::builder::Step::NewLine);
}
crate::config::Layout::Wide => {
steps
.push_back(crate::builder::Step::Format(child.element));
}
if vertical {
steps.push_back(crate::builder::Step::FormatWider(
child.element,
));
steps.push_back(crate::builder::Step::NewLine);
} else {
steps.push_back(crate::builder::Step::Format(child.element));
}
}
}

View file

@ -19,16 +19,12 @@ pub fn rule(
if text == "\"" {
while let Some(child) = children.get_next() {
match build_ctx.config.layout() {
crate::config::Layout::Tall => {
steps.push_back(crate::builder::Step::FormatWider(
child.element,
));
}
crate::config::Layout::Wide => {
steps
.push_back(crate::builder::Step::Format(child.element));
}
if build_ctx.vertical {
steps.push_back(crate::builder::Step::FormatWider(
child.element,
));
} else {
steps.push_back(crate::builder::Step::Format(child.element));
}
}
} else {

View file

@ -8,22 +8,17 @@ pub fn rule(
build_ctx, node, true,
);
let layout = if children.has_comments() || children.has_newlines() {
&crate::config::Layout::Tall
} else {
build_ctx.config.layout()
};
let vertical = children.has_comments()
|| children.has_newlines()
|| build_ctx.vertical;
// ${
let child = children.get_next().unwrap();
steps.push_back(crate::builder::Step::Format(child.element));
match layout {
crate::config::Layout::Tall => {
steps.push_back(crate::builder::Step::Indent);
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
}
crate::config::Layout::Wide => {}
if vertical {
steps.push_back(crate::builder::Step::Indent);
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
}
// /**/
@ -38,13 +33,10 @@ pub fn rule(
// expr
let child = children.get_next().unwrap();
match layout {
crate::config::Layout::Tall => {
steps.push_back(crate::builder::Step::FormatWider(child.element));
}
crate::config::Layout::Wide => {
steps.push_back(crate::builder::Step::Format(child.element));
}
if vertical {
steps.push_back(crate::builder::Step::FormatWider(child.element));
} else {
steps.push_back(crate::builder::Step::Format(child.element));
}
// /**/
@ -59,13 +51,10 @@ pub fn rule(
// }
let child = children.get_next().unwrap();
match layout {
crate::config::Layout::Tall => {
steps.push_back(crate::builder::Step::Dedent);
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
}
crate::config::Layout::Wide => {}
if vertical {
steps.push_back(crate::builder::Step::Dedent);
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
}
steps.push_back(crate::builder::Step::Format(child.element));

View file

@ -4,8 +4,6 @@ use std::io::Write;
fn cases() {
let should_update = std::env::var("UPDATE").is_ok();
let config = alejandra_engine::config::Config::default();
let cases: std::collections::HashSet<String> =
std::fs::read_dir("tests/cases")
.unwrap()
@ -17,7 +15,6 @@ fn cases() {
let path_out = format!("tests/cases/{}/out", case);
let content_in = std::fs::read_to_string(path_in.clone()).unwrap();
let content_got = alejandra_engine::format::string_or_passthrough(
&config,
path_in,
content_in.clone(),
);