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

feat: brace like after pattern entry

This commit is contained in:
Kevin Amado 2022-02-18 18:03:38 -05:00
parent 6a08ca8e43
commit 2a0c9fa66b
No known key found for this signature in database
GPG key ID: FFF341057F503148
4 changed files with 54 additions and 11 deletions

View file

@ -91,6 +91,18 @@ Types of changes
+ _
```
- Brace-like elements after a pattern entry now follow the exclamation mark:
```diff
- rootPoolProperties ?
- {
- autoexpand = "on";
- },
+ rootPoolProperties ? {
+ autoexpand = "on";
+ },
```
## [0.2.0] - 2022-02-17
### Added

View file

@ -63,23 +63,33 @@ pub fn rule(
// expr
let child = children.get_next().unwrap();
let single_line = crate::builder::fits_in_single_line(
let mut dedent = false;
if comment {
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
} else if matches!(
child.element.kind(),
rnix::SyntaxKind::NODE_ATTR_SET
| rnix::SyntaxKind::NODE_IDENT
| rnix::SyntaxKind::NODE_PAREN
| rnix::SyntaxKind::NODE_LAMBDA
| rnix::SyntaxKind::NODE_LET_IN
| rnix::SyntaxKind::NODE_LIST
| rnix::SyntaxKind::NODE_LITERAL
| rnix::SyntaxKind::NODE_STRING,
) || crate::builder::fits_in_single_line(
build_ctx,
child.element.clone(),
);
if single_line {
if comment {
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
} else {
steps.push_back(crate::builder::Step::Whitespace);
}
) {
steps.push_back(crate::builder::Step::Whitespace);
} else {
dedent = true;
steps.push_back(crate::builder::Step::Indent);
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
}
match layout {
crate::config::Layout::Tall => {
steps.push_back(crate::builder::Step::FormatWider(
@ -90,7 +100,7 @@ pub fn rule(
steps.push_back(crate::builder::Step::Format(child.element));
}
}
if !single_line {
if dedent {
steps.push_back(crate::builder::Step::Dedent);
}
}

View file

@ -9,6 +9,16 @@
gomod2nix,
mach-nix,
}@inp: _)
({
a ? [
1
2
3
],
b ? {
# ...
}
}: _)
({}: _)
({ a }: _)
({ /**/ }: _)

View file

@ -11,6 +11,17 @@
mach-nix,
} @ inp:
_)
({
a ? [
1
2
3
],
b ? {
# ...
},
}:
_)
({}: _)
({a}: _)
({