Skip to content

Commit

Permalink
Merge pull request #148 from kamadorueda/kamadorueda
Browse files Browse the repository at this point in the history
feat: brace like after pattern entry
  • Loading branch information
kamadorueda authored Feb 18, 2022
2 parents 6a08ca8 + 2a0c9fa commit 0d09692
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 11 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 21 additions & 11 deletions src/rules/pat_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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);
}
}
Expand Down
10 changes: 10 additions & 0 deletions tests/cases/pattern/in
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@
gomod2nix,
mach-nix,
}@inp: _)
({
a ? [
1
2
3
],
b ? {
# ...
}
}: _)
({}: _)
({ a }: _)
({ /**/ }: _)
Expand Down
11 changes: 11 additions & 0 deletions tests/cases/pattern/out
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@
mach-nix,
} @ inp:
_)
({
a ? [
1
2
3
],
b ? {
# ...
},
}:
_)
({}: _)
({a}: _)
({
Expand Down

0 comments on commit 0d09692

Please sign in to comment.