mirror of
https://github.com/RGBCube/alejandra
synced 2025-08-01 21:17:45 +00:00
feat: more uniform family of elements
This commit is contained in:
parent
98626dc544
commit
14c80aa647
8 changed files with 42 additions and 41 deletions
|
@ -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));
|
||||||
|
|
||||||
|
|
|
@ -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,
|
||||||
|
|
|
@ -95,12 +95,7 @@ rec
|
||||||
c = 2;
|
c = 2;
|
||||||
};
|
};
|
||||||
n = pkgs: {};
|
n = pkgs: {};
|
||||||
o =
|
o = {pkgs, ...}: {};
|
||||||
{
|
|
||||||
pkgs,
|
|
||||||
...
|
|
||||||
}:
|
|
||||||
{};
|
|
||||||
|
|
||||||
a
|
a
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -18,7 +18,8 @@
|
||||||
}:
|
}:
|
||||||
_)
|
_)
|
||||||
({...}: _)
|
({...}: _)
|
||||||
({ ...
|
({
|
||||||
|
...
|
||||||
/**/
|
/**/
|
||||||
}:
|
}:
|
||||||
_)
|
_)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue