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

feat: key-value without max-width

This commit is contained in:
Kevin Amado 2022-02-09 19:48:41 -05:00
parent 779ae36a60
commit 98cf2ef1df
No known key found for this signature in database
GPG key ID: FFF341057F503148
4 changed files with 51 additions and 18 deletions

View file

@ -33,8 +33,7 @@
version =
let
commit = inputs.self.shortRev or "dirty";
date =
inputs.self.lastModifiedDate or inputs.self.lastModified or "19700101";
date = inputs.self.lastModifiedDate or inputs.self.lastModified or "19700101";
in
"${builtins.substring 0 8 date}_${commit}";
src = inputs.self.sourceInfo;

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()
@ -24,13 +26,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);
@ -107,10 +113,13 @@ pub fn rule(
}
// /**/
children.drain_comments(|text| {
steps.push_back(crate::builder::Step::Comment(text));
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
children.drain_comments_and_newlines(|element| match element {
crate::children::DrainCommentOrNewline::Comment(text) => {
steps.push_back(crate::builder::Step::Comment(text));
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
}
crate::children::DrainCommentOrNewline::Newline(_) => {}
});
// b
@ -125,13 +134,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);

View file

@ -21,6 +21,13 @@ rec /**/ {
, ...
}: { };
a
/*b*/
=
/*c*/
1
/*d*/
;
p = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa { }
a;

View file

@ -101,6 +101,20 @@ rec
}:
{ };
a
/*
b
*/
=
/*
c
*/
1
/*
d
*/
;
p =
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa { } a;
}