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

feat: more uniform family of elements

This commit is contained in:
Kevin Amado 2022-02-18 13:02:27 -05:00
parent 98626dc544
commit 14c80aa647
No known key found for this signature in database
GPG key ID: FFF341057F503148
8 changed files with 42 additions and 41 deletions

View file

@ -116,7 +116,9 @@ pub fn rule(
));
}
crate::config::Layout::Wide => {
steps.push_back(crate::builder::Step::Whitespace);
if item_index > 1 {
steps.push_back(crate::builder::Step::Whitespace);
}
steps
.push_back(crate::builder::Step::Format(child.element));
}
@ -135,11 +137,7 @@ pub fn rule(
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
}
crate::config::Layout::Wide => {
if items_count > 0 {
steps.push_back(crate::builder::Step::Whitespace);
}
}
crate::config::Layout::Wide => {}
}
steps.push_back(crate::builder::Step::Format(child.element));

View file

@ -28,6 +28,15 @@ pub fn rule(
})
.count();
let max_items = if node
.children_with_tokens()
.any(|element| element.kind() == rnix::SyntaxKind::TOKEN_ELLIPSIS)
{
2
} else {
1
};
let layout = if has_comments || children.has_newlines() {
&crate::config::Layout::Tall
} else {
@ -103,19 +112,22 @@ pub fn rule(
rnix::SyntaxKind::TOKEN_ELLIPSIS
| rnix::SyntaxKind::NODE_PAT_ENTRY => {
if let rnix::SyntaxKind::TOKEN_CURLY_B_OPEN = last_kind {
if items_count > 1 {
if has_comments_between_curly_b || items_count > max_items {
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
} else {
steps.push_back(crate::builder::Step::Whitespace);
}
}
if let rnix::SyntaxKind::TOKEN_COMMA
| rnix::SyntaxKind::TOKEN_COMMENT = last_kind
{
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
if !has_comments_between_curly_b && items_count <= max_items
{
steps.push_back(crate::builder::Step::Whitespace);
} else {
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
}
}
match layout {
@ -135,9 +147,7 @@ pub fn rule(
}
// ,
rnix::SyntaxKind::TOKEN_COMMA => {
if let rnix::SyntaxKind::TOKEN_COMMA
| rnix::SyntaxKind::TOKEN_COMMENT = last_kind
{
if let rnix::SyntaxKind::TOKEN_COMMENT = last_kind {
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
}
@ -158,10 +168,7 @@ pub fn rule(
// }
let child = children.get_next().unwrap();
steps.push_back(crate::builder::Step::Dedent);
if !has_comments_between_curly_b && items_count == 1 {
steps.push_back(crate::builder::Step::Whitespace);
} else if !has_comments_between_curly_b && items_count == 0 {
} else {
if has_comments_between_curly_b || items_count > max_items {
if let rnix::SyntaxKind::NODE_PAT_ENTRY = last_kind {
steps.push_back(crate::builder::Step::Token(
rnix::SyntaxKind::TOKEN_COMMA,

View file

@ -5,12 +5,12 @@
a
*/
}
{ a = 1; }
{a = 1;}
{
a = 1;
}
{ b = 1; }
{b = 1;}
{
b = 1;
/*
@ -33,7 +33,7 @@
*/
}
rec { c = 1; }
rec {c = 1;}
rec {
c = 1;
/*
@ -101,7 +101,7 @@
a = {
a = rec {
a = {
a = rec { a = { a = rec { a = { a = rec { a = {}; }; }; }; }; };
a = rec {a = {a = rec {a = {a = rec {a = {};};};};};};
};
};
};

View file

@ -7,7 +7,7 @@
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
;
}
{ inherit b d; }
{inherit b d;}
{
inherit
b

View file

@ -1,5 +1,5 @@
[
{ inherit (c) f h; }
{inherit (c) f h;}
{
inherit
(c)

View file

@ -1,7 +1,7 @@
rec
/**/
{
a = { a = 1; };
a = {a = 1;};
b = {
a =
@ -76,7 +76,7 @@ rec
*/
;
};
j = a: { b = 1; };
j = a: {b = 1;};
k = a: {
b = 1;
c = 2;
@ -85,7 +85,7 @@ rec
/*
b
*/
{ b = 1; };
{b = 1;};
m = a:
/*
b
@ -95,12 +95,7 @@ rec
c = 2;
};
n = pkgs: {};
o =
{
pkgs,
...
}:
{};
o = {pkgs, ...}: {};
a
/*

View file

@ -12,13 +12,14 @@
} @ inp:
_)
({}: _)
({ a }: _)
({a}: _)
({
/**/
}:
_)
({ ... }: _)
({ ...
({...}: _)
({
...
/**/
}:
_)
@ -1059,7 +1060,7 @@
}:
_)
({ a ? null }: _)
({a ? null}: _)
({
/*
a

View file

@ -21,9 +21,9 @@
c)
(with b; cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc)
(with b; cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc)
{ a = with b; 1; }
{ a = with b; 1 + 1; }
{ a = with b; { c = 1; }; }
{a = with b; 1;}
{a = with b; 1 + 1;}
{a = with b; {c = 1;};}
{
a = with b; {
c = 1;
@ -40,7 +40,7 @@
a = with b; 1;
# comment
}
(with a; with b; with c; { a = 1; })
(with a; with b; with c; {a = 1;})
(with a;
with b;
with c; {