1
Fork 0
mirror of https://github.com/RGBCube/alejandra synced 2025-08-01 21:17:45 +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 ## [0.2.0] - 2022-02-17
### Added ### Added

View file

@ -63,23 +63,33 @@ pub fn rule(
// expr // expr
let child = children.get_next().unwrap(); 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, build_ctx,
child.element.clone(), child.element.clone(),
); ) {
steps.push_back(crate::builder::Step::Whitespace);
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);
}
} else { } else {
dedent = true;
steps.push_back(crate::builder::Step::Indent); steps.push_back(crate::builder::Step::Indent);
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 => {
steps.push_back(crate::builder::Step::FormatWider( steps.push_back(crate::builder::Step::FormatWider(
@ -90,7 +100,7 @@ pub fn rule(
steps.push_back(crate::builder::Step::Format(child.element)); steps.push_back(crate::builder::Step::Format(child.element));
} }
} }
if !single_line { if dedent {
steps.push_back(crate::builder::Step::Dedent); steps.push_back(crate::builder::Step::Dedent);
} }
} }

View file

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

View file

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