mirror of
https://github.com/RGBCube/alejandra
synced 2025-08-01 04:57:44 +00:00
Merge pull request #140 from kamadorueda/kamadorueda
feat: more uniform family of elements
This commit is contained in:
commit
ea3a5d9d92
8 changed files with 42 additions and 41 deletions
|
@ -116,7 +116,9 @@ pub fn rule(
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
crate::config::Layout::Wide => {
|
crate::config::Layout::Wide => {
|
||||||
steps.push_back(crate::builder::Step::Whitespace);
|
if item_index > 1 {
|
||||||
|
steps.push_back(crate::builder::Step::Whitespace);
|
||||||
|
}
|
||||||
steps
|
steps
|
||||||
.push_back(crate::builder::Step::Format(child.element));
|
.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::NewLine);
|
||||||
steps.push_back(crate::builder::Step::Pad);
|
steps.push_back(crate::builder::Step::Pad);
|
||||||
}
|
}
|
||||||
crate::config::Layout::Wide => {
|
crate::config::Layout::Wide => {}
|
||||||
if items_count > 0 {
|
|
||||||
steps.push_back(crate::builder::Step::Whitespace);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
steps.push_back(crate::builder::Step::Format(child.element));
|
steps.push_back(crate::builder::Step::Format(child.element));
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,15 @@ pub fn rule(
|
||||||
})
|
})
|
||||||
.count();
|
.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() {
|
let layout = if has_comments || children.has_newlines() {
|
||||||
&crate::config::Layout::Tall
|
&crate::config::Layout::Tall
|
||||||
} else {
|
} else {
|
||||||
|
@ -103,19 +112,22 @@ pub fn rule(
|
||||||
rnix::SyntaxKind::TOKEN_ELLIPSIS
|
rnix::SyntaxKind::TOKEN_ELLIPSIS
|
||||||
| rnix::SyntaxKind::NODE_PAT_ENTRY => {
|
| rnix::SyntaxKind::NODE_PAT_ENTRY => {
|
||||||
if let rnix::SyntaxKind::TOKEN_CURLY_B_OPEN = last_kind {
|
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::NewLine);
|
||||||
steps.push_back(crate::builder::Step::Pad);
|
steps.push_back(crate::builder::Step::Pad);
|
||||||
} else {
|
|
||||||
steps.push_back(crate::builder::Step::Whitespace);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let rnix::SyntaxKind::TOKEN_COMMA
|
if let rnix::SyntaxKind::TOKEN_COMMA
|
||||||
| rnix::SyntaxKind::TOKEN_COMMENT = last_kind
|
| rnix::SyntaxKind::TOKEN_COMMENT = last_kind
|
||||||
{
|
{
|
||||||
steps.push_back(crate::builder::Step::NewLine);
|
if !has_comments_between_curly_b && items_count <= max_items
|
||||||
steps.push_back(crate::builder::Step::Pad);
|
{
|
||||||
|
steps.push_back(crate::builder::Step::Whitespace);
|
||||||
|
} else {
|
||||||
|
steps.push_back(crate::builder::Step::NewLine);
|
||||||
|
steps.push_back(crate::builder::Step::Pad);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
match layout {
|
match layout {
|
||||||
|
@ -135,9 +147,7 @@ pub fn rule(
|
||||||
}
|
}
|
||||||
// ,
|
// ,
|
||||||
rnix::SyntaxKind::TOKEN_COMMA => {
|
rnix::SyntaxKind::TOKEN_COMMA => {
|
||||||
if let rnix::SyntaxKind::TOKEN_COMMA
|
if let rnix::SyntaxKind::TOKEN_COMMENT = last_kind {
|
||||||
| rnix::SyntaxKind::TOKEN_COMMENT = last_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);
|
||||||
}
|
}
|
||||||
|
@ -158,10 +168,7 @@ pub fn rule(
|
||||||
// }
|
// }
|
||||||
let child = children.get_next().unwrap();
|
let child = children.get_next().unwrap();
|
||||||
steps.push_back(crate::builder::Step::Dedent);
|
steps.push_back(crate::builder::Step::Dedent);
|
||||||
if !has_comments_between_curly_b && items_count == 1 {
|
if has_comments_between_curly_b || items_count > max_items {
|
||||||
steps.push_back(crate::builder::Step::Whitespace);
|
|
||||||
} else if !has_comments_between_curly_b && items_count == 0 {
|
|
||||||
} else {
|
|
||||||
if let rnix::SyntaxKind::NODE_PAT_ENTRY = last_kind {
|
if let rnix::SyntaxKind::NODE_PAT_ENTRY = last_kind {
|
||||||
steps.push_back(crate::builder::Step::Token(
|
steps.push_back(crate::builder::Step::Token(
|
||||||
rnix::SyntaxKind::TOKEN_COMMA,
|
rnix::SyntaxKind::TOKEN_COMMA,
|
||||||
|
|
|
@ -5,12 +5,12 @@
|
||||||
a
|
a
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
{ a = 1; }
|
{a = 1;}
|
||||||
{
|
{
|
||||||
a = 1;
|
a = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
{ b = 1; }
|
{b = 1;}
|
||||||
{
|
{
|
||||||
b = 1;
|
b = 1;
|
||||||
/*
|
/*
|
||||||
|
@ -33,7 +33,7 @@
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
rec { c = 1; }
|
rec {c = 1;}
|
||||||
rec {
|
rec {
|
||||||
c = 1;
|
c = 1;
|
||||||
/*
|
/*
|
||||||
|
@ -101,7 +101,7 @@
|
||||||
a = {
|
a = {
|
||||||
a = rec {
|
a = rec {
|
||||||
a = {
|
a = {
|
||||||
a = rec { a = { a = rec { a = { a = rec { a = {}; }; }; }; }; };
|
a = rec {a = {a = rec {a = {a = rec {a = {};};};};};};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
{ inherit b d; }
|
{inherit b d;}
|
||||||
{
|
{
|
||||||
inherit
|
inherit
|
||||||
b
|
b
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
[
|
[
|
||||||
{ inherit (c) f h; }
|
{inherit (c) f h;}
|
||||||
{
|
{
|
||||||
inherit
|
inherit
|
||||||
(c)
|
(c)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
rec
|
rec
|
||||||
/**/
|
/**/
|
||||||
{
|
{
|
||||||
a = { a = 1; };
|
a = {a = 1;};
|
||||||
|
|
||||||
b = {
|
b = {
|
||||||
a =
|
a =
|
||||||
|
@ -76,7 +76,7 @@ rec
|
||||||
*/
|
*/
|
||||||
;
|
;
|
||||||
};
|
};
|
||||||
j = a: { b = 1; };
|
j = a: {b = 1;};
|
||||||
k = a: {
|
k = a: {
|
||||||
b = 1;
|
b = 1;
|
||||||
c = 2;
|
c = 2;
|
||||||
|
@ -85,7 +85,7 @@ rec
|
||||||
/*
|
/*
|
||||||
b
|
b
|
||||||
*/
|
*/
|
||||||
{ b = 1; };
|
{b = 1;};
|
||||||
m = a:
|
m = a:
|
||||||
/*
|
/*
|
||||||
b
|
b
|
||||||
|
@ -95,12 +95,7 @@ rec
|
||||||
c = 2;
|
c = 2;
|
||||||
};
|
};
|
||||||
n = pkgs: {};
|
n = pkgs: {};
|
||||||
o =
|
o = {pkgs, ...}: {};
|
||||||
{
|
|
||||||
pkgs,
|
|
||||||
...
|
|
||||||
}:
|
|
||||||
{};
|
|
||||||
|
|
||||||
a
|
a
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -12,13 +12,14 @@
|
||||||
} @ inp:
|
} @ inp:
|
||||||
_)
|
_)
|
||||||
({}: _)
|
({}: _)
|
||||||
({ a }: _)
|
({a}: _)
|
||||||
({
|
({
|
||||||
/**/
|
/**/
|
||||||
}:
|
}:
|
||||||
_)
|
_)
|
||||||
({ ... }: _)
|
({...}: _)
|
||||||
({ ...
|
({
|
||||||
|
...
|
||||||
/**/
|
/**/
|
||||||
}:
|
}:
|
||||||
_)
|
_)
|
||||||
|
@ -1059,7 +1060,7 @@
|
||||||
}:
|
}:
|
||||||
_)
|
_)
|
||||||
|
|
||||||
({ a ? null }: _)
|
({a ? null}: _)
|
||||||
({
|
({
|
||||||
/*
|
/*
|
||||||
a
|
a
|
||||||
|
|
|
@ -21,9 +21,9 @@
|
||||||
c)
|
c)
|
||||||
(with b; cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc)
|
(with b; cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc)
|
||||||
(with b; cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc)
|
(with b; cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc)
|
||||||
{ a = with b; 1; }
|
{a = with b; 1;}
|
||||||
{ a = with b; 1 + 1; }
|
{a = with b; 1 + 1;}
|
||||||
{ a = with b; { c = 1; }; }
|
{a = with b; {c = 1;};}
|
||||||
{
|
{
|
||||||
a = with b; {
|
a = with b; {
|
||||||
c = 1;
|
c = 1;
|
||||||
|
@ -40,7 +40,7 @@
|
||||||
a = with b; 1;
|
a = with b; 1;
|
||||||
# comment
|
# comment
|
||||||
}
|
}
|
||||||
(with a; with b; with c; { a = 1; })
|
(with a; with b; with c; {a = 1;})
|
||||||
(with a;
|
(with a;
|
||||||
with b;
|
with b;
|
||||||
with c; {
|
with c; {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue