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

feat: or default without max-width

This commit is contained in:
Kevin Amado 2022-02-09 20:32:59 -05:00
parent 9d95a93051
commit 94bc85ced1
No known key found for this signature in database
GPG key ID: FFF341057F503148

View file

@ -4,9 +4,11 @@ pub fn rule(
) -> std::collections::LinkedList<crate::builder::Step> {
let mut steps = std::collections::LinkedList::new();
let mut children = crate::children::Children::new(build_ctx, node);
let mut children = crate::children::Children::new_with_configuration(
build_ctx, node, true,
);
let layout = if children.has_comments() {
let layout = if children.has_comments() || children.has_newlines() {
&crate::config::Layout::Tall
} else {
build_ctx.config.layout()
@ -35,13 +37,17 @@ pub fn rule(
}
// /**/
children.drain_comments(|text| {
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
steps.push_back(crate::builder::Step::Comment(text));
children.drain_comments_and_newlines(|element| match element {
crate::children::DrainCommentOrNewline::Comment(text) => {
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
steps.push_back(crate::builder::Step::Comment(text));
}
crate::children::DrainCommentOrNewline::Newline(_) => {}
});
if let rnix::SyntaxKind::TOKEN_COMMENT =
if let rnix::SyntaxKind::TOKEN_COMMENT
| rnix::SyntaxKind::TOKEN_WHITESPACE =
children.peek_prev().unwrap().element.kind()
{
steps.push_back(crate::builder::Step::NewLine);
@ -55,13 +61,17 @@ pub fn rule(
steps.push_back(crate::builder::Step::Format(child.element));
// /**/
children.drain_comments(|text| {
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
steps.push_back(crate::builder::Step::Comment(text));
children.drain_comments_and_newlines(|element| match element {
crate::children::DrainCommentOrNewline::Comment(text) => {
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
steps.push_back(crate::builder::Step::Comment(text));
}
crate::children::DrainCommentOrNewline::Newline(_) => {}
});
if let rnix::SyntaxKind::TOKEN_COMMENT =
if let rnix::SyntaxKind::TOKEN_COMMENT
| rnix::SyntaxKind::TOKEN_WHITESPACE =
children.peek_prev().unwrap().element.kind()
{
steps.push_back(crate::builder::Step::NewLine);