1
Fork 0
mirror of https://github.com/RGBCube/alejandra synced 2025-08-01 04:57:44 +00:00

feat: apply without max-width

This commit is contained in:
Kevin Amado 2022-02-09 20:14:27 -05:00
parent f179b2e855
commit d2e2f6c20b
No known key found for this signature in database
GPG key ID: FFF341057F503148
4 changed files with 51 additions and 25 deletions

View file

@ -4,9 +4,11 @@ pub fn rule(
) -> std::collections::LinkedList<crate::builder::Step> { ) -> std::collections::LinkedList<crate::builder::Step> {
let mut steps = std::collections::LinkedList::new(); 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 &crate::config::Layout::Tall
} else { } else {
build_ctx.config.layout() build_ctx.config.layout()
@ -24,10 +26,13 @@ pub fn rule(
} }
// /**/ // /**/
children.drain_comments(|text| { children.drain_comments_and_newlines(|element| match element {
steps.push_back(crate::builder::Step::NewLine); crate::children::DrainCommentOrNewline::Comment(text) => {
steps.push_back(crate::builder::Step::Pad); steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Comment(text)); steps.push_back(crate::builder::Step::Pad);
steps.push_back(crate::builder::Step::Comment(text));
}
crate::children::DrainCommentOrNewline::Newline(_) => {}
}); });
let child_prev = children.peek_prev().unwrap(); let child_prev = children.peek_prev().unwrap();
@ -36,7 +41,9 @@ pub fn rule(
let child = children.get_next().unwrap(); let child = children.get_next().unwrap();
match layout { match layout {
crate::config::Layout::Tall => { crate::config::Layout::Tall => {
if let rnix::SyntaxKind::TOKEN_COMMENT = child_prev.element.kind() { 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::NewLine);
steps.push_back(crate::builder::Step::Pad); steps.push_back(crate::builder::Step::Pad);
} else if let rnix::SyntaxKind::NODE_ATTR_SET } else if let rnix::SyntaxKind::NODE_ATTR_SET

View file

@ -1,10 +1,13 @@
(a b) (a b) ( (a b)
(a b)
(
a a
/* /*
b b
*/ */
c c
) ( )
(
/* /*
a a
*/ */

View file

@ -116,5 +116,6 @@ rec
; ;
p = p =
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa { } a; aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa { }
a;
} }

View file

@ -1,17 +1,20 @@
( (
((c)) ( ((c))
(
(c) (c)
/* /*
e e
*/ */
) ( )
(
( (
c c
/* /*
d d
*/ */
) )
) ( )
(
( (
c c
/* /*
@ -21,14 +24,16 @@
/* /*
e e
*/ */
) ( )
(
( (
/* /*
b b
*/ */
c c
) )
) ( )
(
( (
/* /*
b b
@ -38,7 +43,8 @@
/* /*
e e
*/ */
) ( )
(
( (
/* /*
b b
@ -48,7 +54,8 @@
d d
*/ */
) )
) ( )
(
( (
/* /*
b b
@ -61,12 +68,14 @@
/* /*
e e
*/ */
) ( )
(
/* /*
a a
*/ */
(c) (c)
) ( )
(
/* /*
a a
*/ */
@ -74,7 +83,8 @@
/* /*
e e
*/ */
) ( )
(
/* /*
a a
*/ */
@ -84,7 +94,8 @@
d d
*/ */
) )
) ( )
(
/* /*
a a
*/ */
@ -97,7 +108,8 @@
/* /*
e e
*/ */
) ( )
(
/* /*
a a
*/ */
@ -107,7 +119,8 @@
*/ */
c c
) )
) ( )
(
/* /*
a a
*/ */
@ -120,7 +133,8 @@
/* /*
e e
*/ */
) ( )
(
/* /*
a a
*/ */
@ -133,7 +147,8 @@
d d
*/ */
) )
) ( )
(
/* /*
a a
*/ */