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 => {
|
||||
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));
|
||||
|
||||
|
|
|
@ -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,20 +112,23 @@ 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
|
||||
{
|
||||
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 {
|
||||
crate::config::Layout::Tall => {
|
||||
|
@ -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,
|
||||
|
|
|
@ -95,12 +95,7 @@ rec
|
|||
c = 2;
|
||||
};
|
||||
n = pkgs: {};
|
||||
o =
|
||||
{
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
{};
|
||||
o = {pkgs, ...}: {};
|
||||
|
||||
a
|
||||
/*
|
||||
|
|
|
@ -18,7 +18,8 @@
|
|||
}:
|
||||
_)
|
||||
({...}: _)
|
||||
({ ...
|
||||
({
|
||||
...
|
||||
/**/
|
||||
}:
|
||||
_)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue