1
Fork 0
mirror of https://github.com/RGBCube/alejandra synced 2025-08-01 21:17:45 +00:00

Merge pull request #140 from kamadorueda/kamadorueda

feat: more uniform family of elements
This commit is contained in:
Kevin Amado 2022-02-18 13:09:08 -05:00 committed by GitHub
commit ea3a5d9d92
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 42 additions and 41 deletions

View file

@ -116,7 +116,9 @@ pub fn rule(
)); ));
} }
crate::config::Layout::Wide => { crate::config::Layout::Wide => {
if item_index > 1 {
steps.push_back(crate::builder::Step::Whitespace); 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));

View file

@ -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,20 +112,23 @@ 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
{ {
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::NewLine);
steps.push_back(crate::builder::Step::Pad); steps.push_back(crate::builder::Step::Pad);
} }
}
match layout { match layout {
crate::config::Layout::Tall => { crate::config::Layout::Tall => {
@ -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,

View file

@ -95,12 +95,7 @@ rec
c = 2; c = 2;
}; };
n = pkgs: {}; n = pkgs: {};
o = o = {pkgs, ...}: {};
{
pkgs,
...
}:
{};
a a
/* /*

View file

@ -18,7 +18,8 @@
}: }:
_) _)
({...}: _) ({...}: _)
({ ... ({
...
/**/ /**/
}: }:
_) _)